gpt4 book ai didi

elasticsearch - 弹性查询的 bool 查询

转载 作者:行者123 更新时间:2023-12-02 22:46:31 24 4
gpt4 key购买 nike

我在 flex 搜索中使用 bool(boolean) 查询。我的查询是

curl -XGET 'localhost:9200/population/_search' -d '{
"query":{
"bool" : {
"must" : {
"term" : { "user" : "rahul" }
},
"filter": {
"term" : { "message" : "dsi" }
},
"must_not" : {

"country" : "pakistan"

},
"should" : [
{
"term" : { "country" : "india" }
},
{
"term" : { "state" : "karnataka" }
}
],

"minimum_should_match" : 1,
"boost" : 1.0
}}

}'

用户,州,国家是我的 flex 搜索中的字段。
但出现错误。
    {"error":{"root_cause":[{"type":"query_parsing_exception","reason":"[_na] query malformed, no field after start_object","index":"population","line":13,"col":17}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"population","node":"bECY7K9ORPSuLrXpL1DpDw","reason":{"type":"query_parsing_exception","reason":"[_na] query malformed, no field after start_object","index":"population","line":13,"col":17}}]},"status":400}

最佳答案

您的bool/must_not子句不正确,您缺少term查询

curl -XGET 'localhost:9200/population/_search' -d '{
"query":{
"bool" : {
"must" : {
"term" : { "user" : "rahul" }
},
"filter": {
"term" : { "message" : "dsi" }
},
"must_not" : {
"term": { "country" : "pakistan" } <--- change this line
},
"should" : [
{
"term" : { "country" : "india" }
},
{
"term" : { "state" : "karnataka" }
}
],

"minimum_should_match" : 1,
"boost" : 1.0
}}

}'

关于elasticsearch - 弹性查询的 bool 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37256307/

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