[英]elasticsearch range filter for array field
I have a field containing an array of integers eg: 我有一个包含整数数组的字段,例如:
_source: {
...
prices: [
20001,
30001
]
}
I'd like to filter the results such that prices contains at least one of a list of values which are between eg: [20002,30000] #
would not return the above document because no value is between 20002 and 30000 but [10000,20002]
would return above document because 20001 in the prices field of above document is between 10000 and 20002 我想过滤结果,使得价格至少包含一个值列表,例如: [20002,30000] #
不会返回上述文档,因为20002和30000之间没有值,但是[10000,20002]
将返回上面的文件,因为20001在上述文件的价格字段中介于10000和20002之间
Elasticsearch always considers that a field can contain a list of values so, a range filter should work. Elasticsearch始终认为字段可以包含值列表,因此范围过滤器应该起作用。 If any of the values matches the range it will be filtered in. 如果任何值与范围匹配,则将对其进行过滤。
You can use that filter as part of a filtered query : 您可以将该过滤器用作过滤查询的一部分:
{
"query": {
"filtered": {
"filter": {
"range": {
"prices": {
"gte": 10000,
"lte": 20002
}
}
}
}
}
}
However, filtered query is deprecated in 2.0, so, if you are using 2.0 you can better use a bool query with a filter: 但是,过滤查询在2.0中已弃用,因此,如果您使用的是2.0,则可以更好地将bool查询与过滤器一起使用:
{
"query": {
"bool": {
"must": {
"match_all": {}
},
"filter": {
"range": {
"prices": {
"gte": 10000,
"lte": 20002
}
}
}
}
}
}
Note that I'm using a filter in my examples because you asked for a filter :) 请注意,我在我的示例中使用了一个过滤器,因为您要求使用过滤器:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.