gpt4 book ai didi

elasticsearch - 在ElasticSearch Java APi中组合QueryParameters

转载 作者:行者123 更新时间:2023-12-02 22:56:38 25 4
gpt4 key购买 nike

我有要搜索的json对象,看起来像这样
我目前能够进行一系列价格搜索,但我想按城市添加搜索,这是出发对象的属性,因此我决定进行嵌套查询,但出现错误

我的ES日志显示

e_synonyms_phrase_query":true,"boost":1.0}}}],"adjust_pure_negative":true,"boost":1.0}},"path":"departure","ignore_unmapped":false,"score_mode":"avg","boost":1.0}}],"adjust_pure_negative":true,"boost":1.0}}}}] lastShard [true]
org.elasticsearch.transport.RemoteTransportException: [AoBfpnE][127.0.0.1:9300][indices:data/read/search[phase/query]]
Caused by: org.elasticsearch.index.query.QueryShardException: failed to create query: {
"bool" : {
"filter" : [
{
"range" : {
"price" : {
"from" : 1300,
"to" : 5000,
"include_lower" : true,
"include_upper" : true,
"boost" : 1.0
}
}
},
{
"nested" : {
"query" : {
"bool" : {
"must" : [
{
"match" : {
"departure.city" : {
"query" : "minsk",
"operator" : "OR",
"prefix_length" : 0,
"max_expansions" : 50,
"fuzzy_transpositions" : true,
"lenient" : false,
"zero_terms_query" : "NONE",
"auto_generate_synonyms_phrase_query" : true,
"boost" : 1.0
}
}
}
],
"adjust_pure_negative" : true,
"boost" : 1.0
}
},
"path" : "departure",
"ignore_unmapped" : false,
"score_mode" : "avg",
"boost" : 1.0
}
}
],
"adjust_pure_negative" : true,
"boost" : 1.0
}
}
at org.elasticsearch.index.query.QueryShardContext.toQuery(QueryShardContext.java:320) ~[elasticsearch-6.3.2.jar:6.3.2]
at org.elasticsearch.index.query.QueryShardContext.toQuery(QueryShardContext.java:303) ~[elasticsearch-6.3.2.jar:6.3.2]

最佳答案

正确的查询如下所示:

    QueryBuilder range = QueryBuilders.rangeQuery("price")
.from(minPrice)
.to(maxPrice)
.includeLower(true)
.includeUpper(true);

QueryBuilder city = QueryBuilders.matchQuery("departure.city", city);

QueryBuilder query = QueryBuilders.boolQuery()
.filter(range)
.filter(city);

...

searchSourceBuilder.query(query);

关于elasticsearch - 在ElasticSearch Java APi中组合QueryParameters,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51668825/

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