elasticsearch-具有多个条件的术语过滤器 [英] elasticsearch - Terms filter with multiple condition
本文介绍了elasticsearch-具有多个条件的术语过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想一次击中ES即可搜索具有2个或更多条件的多个值.
I want to achieve searching for multiple values with 2 or more conditions in one hit to ES.
例如,客户"索引具有2个字段userid和order
.我使用下面的查询来搜索匹配两个字段的结果.
For Eg, "customer" index has 2 fields userid and order
. I used below query to search results matching both fields.
`{
"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
).我们可以使用条款过滤器或其他替代方法来实现这一目标吗?
the result matched documents satisfying all combinations(like 1&A, 1&B, 2&A, 2&B
). But i need the results matching only in the order sent(like 1&A, 2&B
). Can we achieve this with Terms Filter or any other alternative?
推荐答案
您始终可以使用嵌套的"and"
s和"or"
s:
You can always use nested "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" } } }
]}
]
}
}
}
}
}
这篇关于elasticsearch-具有多个条件的术语过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文