Hibernate搜索向请求添加相关ID

tjvv9vkg  于 2022-11-24  发布在  其他
关注(0)|答案(1)|浏览(109)

我一直在尝试在Hibernate搜索中添加关联ID。尝试按照文档中给出的那样创建自定义HTTP客户端配置。但是它不起作用。

@Configuration
public class HttpClientConfigurer implements ElasticsearchHttpClientConfigurer {

    @Override
    public void configure(ElasticsearchHttpClientConfigurationContext context) {
        System.out.println("Setting the correlationId");
        MDC.put("correlationId", UUID.randomUUID().toString());
        System.out.println("The correlationId is set");
        HttpAsyncClientBuilder clientBuilder = context.clientBuilder();
        clientBuilder.setMaxConnPerRoute( 7 );
        clientBuilder.addInterceptorFirst( (HttpResponseInterceptor) (request, httpContext) -> {
            System.out.println("Checkpoint 2");
        } );
        clientBuilder.build();
    }
}

在属性中添加了以下内容:

elasticsearch.search.backend.client.configurer = com.broadridge.basmsp.configuration.HttpClientConfigurer

需要在请求中的此处添加相关ID:

2022-09-26 12:51:33.132 TRACE [     ] 11712 --- [port thread - 1] o.h.search.elasticsearch.request         : HSEARCH400093: Executed Elasticsearch HTTP POST request to 'http://localhost:9200' with path 'read', query parameters {from=0, size=25, track_total_hits=true} and 1 objects in payload in 15ms. Response had status 200 'OK'. Request body: <{"query":{"bool":{"must":{"bool":POST}...},"hits":{"total":{"value":0,"relation":"eq"},"hits":[]}}>
dgsult0t

dgsult0t1#

您的配置属性无效:

elasticsearch.search.backend.client.configurer

应道:

hibernate.search.backend.client.configurer

相关问题