elasticsearch 如何使用弹性搜索获得同时满足两个查询条件的文档
尝试框架弹性查询以获取同时具有这两个查询文件值的文档,例如,我希望文档或数据的国家为“india”,财富为“12或10或09” 我试图在下面构建查询,但没有得到预期的结果
elasticsearch 如何使用弹性搜索获得同时满足两个查询条件的文档,
elasticsearch,
elasticsearch,尝试框架弹性查询以获取同时具有这两个查询文件值的文档,例如,我希望文档或数据的国家为“india”,财富为“12或10或09” 我试图在下面构建查询,但没有得到预期的结果 { "query": { "nested": { "path": "person_details", "query": { "bool": { "should": [ { "match": {"person_details.weat
{
"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"
}
]
}
}
}
}
}
低于解析错误
{
“消息”:“错误的请求:无效的Json,异常为groovy.Json.JsonException:应为'}'或',但得到的当前字符'q'的int值为113\n\n当前读取的字符是'q'的int值为113\n期望'}'或','但得到的当前字符'q'的int值为113\n行数2\n索引数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"
}
]
}
}