学习elasticsearch的时候,想要查看elasticsearch发送的DSL语句,类似MyBatis可以在idea的控制台上输出Mysql语句,可以添加如下配置

一、配置RestHighLevelClient

/**
 * @author wfd
 * @description
 * @create 2021/3/7 23:10
 */
@Configuration
public class EsConfig {

	// @Bean
	// public RestHighLevelClient restHighLevelClient() {
	// 	return new RestHighLevelClient(
	// 			RestClient.builder(
	// 					new HttpHost("192.168.126.130", 9200, "http")));
	// }
	
	// 将RestHighLevelClient 修改成这种方式
	@Bean(destroyMethod = "close")
	public RestHighLevelClient restClient() {

		ClientConfiguration clientConfiguration = ClientConfiguration.builder()
				.connectedTo("192.168.126.130:9200")
				.build();

		RestHighLevelClient client = RestClients.create(clientConfiguration).rest();
		return client;
	}
}

二、在application.yml添加日志输出

logging:
  level:
    org.springframework.data.elasticsearch.client.WIRE: TRACE

三、效果
在这里插入图片描述

注意:本文使用 Springboot 2.4.3,、RestHighLevelClient,elasticsearch使用的是 7.9.3

参考资料:https://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/#reference

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐