我在弹性搜索中使用布尔查询。我的疑问是
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
}}
}'
用户,州,国家/地区在我的弹性搜索中是字段。 但是收到错误。
{"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}
答案 0 :(得分:4)
您的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
}}
}'