gpt4 book ai didi

Java Elasticsearch - 具有存在条件的 Boolquery

转载 作者:太空宇宙 更新时间:2023-11-04 09:50:48 26 4
gpt4 key购买 nike

我有以下代码,我需要在某些字段中获得非空结果,并检查其他字段中的值。 (我正在使用“RestHighLevelClient”)

但是我收到了这个错误:

Caused by: ElasticsearchStatusException[Elasticsearch exception [type=search_phase_execution_exception, reason=all shards failed]]

....

Suppressed: org.elasticsearch.client.ResponseException: method [POST], host [http://192.168.8.101:9200], URI [/_search?typed_keys=true&ignore_unavailable=false&expand_wildcards=open&allow_no_indices=true&scroll=1m&sear .....

{"error":{"root_cause":[{"type":"query_parsing_exception","reason":"[exists] query does not support [boost]

代码:

SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
BoolQueryBuilder boolQuery = new BoolQueryBuilder();
boolQuery.must(QueryBuilders.existsQuery("usuarioIntegracao"));
boolQuery.must(QueryBuilders.termsQuery("tabela", "Arquivo", "Mensagem"));
boolQuery.must(QueryBuilders.termQuery("statusTexto", "Erro"));
boolQuery.must(QueryBuilders.rangeQuery("dataEntrada")
.from("now-1d/d")
.timeZone("-03:00"));

searchSourceBuilder.query(boolQuery);
searchSourceBuilder.size(9999);
searchSourceBuilder.timeout(new TimeValue(60, TimeUnit.SECONDS));

searchRequest.source(searchSourceBuilder);

SearchResponse response = client.search(searchRequest, RequestOptions.DEFAULT);

我在 Postman 上成功搜索到相同的内容:

{
"size" : 1000,

"sort" : [
{"dataEntrada" : {"order" : "desc"}}
],

"query" : {
"bool":{
"must":[
{"terms":{ "tabela" : ["Arquivo", "Mensagem"] }},

{"term":{ "statusTexto" : "Erro" }},

{"exists" : { "field" : "usuarioIntegracao" }},

{"range" : {
"dataEntrada" : {
"gte" : "now-1d/d",
"lt" : "now/d",
"timeZone" : "-03:00"
}
}}
],
"should":{},
"must_not":{

}
}
}
}

最佳答案

我认为你的问题是语法。试试这个:

BoolQueryBuilder boolQuery = QueryBuilders.boolQuery()
.must(QueryBuilders.existsQuery("usuarioIntegracao"))
.must(QueryBuilders.termsQuery("tabela", "Arquivo", "Mensagem"))
.must(QueryBuilders.termQuery("statusTexto", "Erro"))
.must(QueryBuilders.rangeQuery("dataEntrada").from("now-1d/d").timeZone("-03:00"));

searchSourceBuilder.query(boolQuery);

关于Java Elasticsearch - 具有存在条件的 Boolquery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54785261/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com