elasticsearch range 过滤器
时间: 2023-07-28 12:55:25 浏览: 42
Elasticsearch Range 过滤器是一种用于匹配某个字段范围的过滤器。它可以用于限制搜索结果,只返回满足某个字段在指定范围内的文档,常见的字段类型包括数字、日期和字符串。
Range 过滤器的语法如下:
```
{
"range" : {
"field" : {
"gte" : lower_bound,
"lte" : upper_bound,
"gt" : lower_bound,
"lt" : upper_bound
}
}
}
```
其中,`field` 表示需要过滤的字段名,`gte` 表示大于等于 lower_bound,`lte` 表示小于等于 upper_bound,`gt` 表示大于 lower_bound,`lt` 表示小于 upper_bound。
以下是一个示例,用于查找价格在 10 到 20 之间的商品:
```
GET /products/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"name": "iphone"
}
},
{
"range": {
"price": {
"gte": 10,
"lte": 20
}
}
}
]
}
}
}
```
在上面的示例中,我们使用 `range` 过滤器来匹配价格在 10 到 20 之间的商品,同时使用 `match` 查询来匹配名称包含“iphone”的商品。