[英]How to get documents satisfying both the query terms using elastic search
嘗試構建工作彈性查詢以獲取同時具有這兩個查詢字段值的文檔,例如,我想要國家/地區為“印度”且財富為“ 12或10或09”的文檔或數據
我試圖在下面的框架查詢,但沒有得到預期的結果
{
"query": {
"nested": {
"path": "person_details",
"query": {
"bool": {
"should": [
{ "match": {"person_details.weath": "12"}},
{ "match": {"person_details.weath": "10"}},
{ "match": {"person_details.weath": "09"}}
]
}
},
"query": {
"term": {
"person_details.country": "INDIA"
}
}
}
}
}
因此,例如在后端,他們是四個人,詳細信息如下
person country person wealth
india 12
japan 23
india 10
india 09
US 12
然后形成的彈性查詢必須返回3個人的詳細信息,但是我的框架查詢返回4個條目(也返回美國個人的詳細信息),我的查詢沒有嚴格考慮國家的條件。
關於這個的任何想法請堅持下去。
更新:基於@paqash更新查詢的一個答案
{
query: {
nested: {
path: "product_vendors",
query: {
bool :{
must : [
bool : {
should : [
{ "match": {"product_vendors.manufacturer_style": "123"}},
{ "match": {"product_vendors.manufacturer_style": "345"}}
]
},
term : {
"product_vendors.id": "777"
}
]
}
}
}
}
}
甚至在下面嘗試過
{
"query": {
"nested": {
"path": "product_vendors",
"query": {
"bool" :{
"must" : [
"bool" : {
"should" : [
{ "match": {"product_vendors.manufacturer_style": "123"}},
{ "match": {"product_vendors.manufacturer_style": "345"}}
]
},
"term" : {
"product_vendors.id": "777"
}
]
}
}
}
}
}
低於解析錯誤
{“ message”:“錯誤的請求:無效的Json,異常是groovy.json.JsonException:預期為'}'或',但得到了當前char'q',其int值為113 \\ n \\ n當前讀取的字符為' q'的int值為113 \\ expecting'}'或',',但是得到的當前char'q'的int值為113 \\ nline number 2 \\ nindex number 4 \\ n查詢:{\\ n .. ^“}
您必須在must子句的bool查詢中同時包含兩個查詢。 因此,請替換:
"query": {
"bool": {
"should": [
{ "match": {"person_details.weath": "12"}},
{ "match": {"person_details.weath": "10"}},
{ "match": {"person_details.weath": "09"}}
]
}
},
"query": {
"term": {
"person_details.country": "INDIA"
}
}
有:
query: {
bool: {
must: [
bool: {
should: [
{ "match": {"person_details.weath": "12"}},
{ "match": {"person_details.weath": "10"}},
{ "match": {"person_details.weath": "09"}}
]
},
term: {
"person_details.country": "INDIA"
}
]
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.