SpringDataElasticsearch控制台打印查询语句

/ 默认分类 / 没有评论 / 2010浏览

application.yml增加配置

# 日志配置
logging:
  level: 
    #es日志
    org.springframework.data.elasticsearch.client.WIRE : trace

增加配置类

package com.maruifu.business.config;

import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.client.ClientConfiguration;
import org.springframework.data.elasticsearch.client.RestClients;

/**
 * 用于打印dsl语句
 */
@Configuration
public class EsConfig {
     
    @Bean(destroyMethod = "close")
    public RestHighLevelClient restClient() {

        ClientConfiguration clientConfiguration = ClientConfiguration.builder()
                .connectedTo("172.16.45.138:11700")
                .build();
        RestHighLevelClient client = RestClients.create(clientConfiguration).rest();
        return client;
    }
}

查看打印效果

image-20221215224015543