我想实现一次对ES的搜索具有2个或更多条件的多个值。
For Eg, "customer" index has 2 fields userid and order
。我使用下面的查询来搜索与这两个字段匹配的结果。
`{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"and": [
{
"terms": {
"userid": [
"1","2"
]
}
},
{
"terms": {
"order": [
"A","B"
]
}
}
]
}
}
}
}`
结果匹配满足所有组合的文档(例如1&A, 1&B, 2&A, 2&B
)。但我需要仅按照发送顺序匹配的结果(例如1&A, 2&B
)。我们可以通过术语过滤器或任何其他替代方案来实现这一目标吗?
您始终可以使用嵌套"and"
s and "or"
s:
POST /test_index/_search
{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"or": {
"filters": [
{ "and": [
{ "term": { "userid": { "value": "1" } } },
{ "term": { "order": { "value": "A" } } }
]},
{ "and": [
{ "term": { "userid": { "value": "2" } } },
{ "term": { "order": { "value": "B" } } }
]}
]
}
}
}
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)