如何查询elasticsearch大于和小于? [英] How to query elasticsearch for greater than and less than?

查看:3564
本文介绍了如何查询elasticsearch大于和小于?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取1000到2000之间的值。我尝试了以下查询:

I want to get values between 1000 and 2000. I tried this query:

{
    "query": {
        "bool": {
            "filter": [{
                "range": {
                    "price": {
                        "gte": 1000
                    },
                    "price": {
                        "lte": 2000
                    }
                }
            }]
        }
    }
}

但这不会给出令人满意的结果。大于工作正常。我正在使用elasticsearch v6.3。

But this doesn't give satisfactory results. Greater than works fine. I am using elasticsearch v6.3. Please help with solution for both inclusive and exclusive of both values.

推荐答案

返回价格 值,范围在1000到2000之间(含首尾)。

Returns documents where the price value between 1000 and 2000 inclusive.

{
    "query": {
        "range" : {
            "price" : {
                "gte" : 1000,
                "lte" : 2000
            }
        }
    }
}




范围查询

匹配条件范围在一定范围内的文档。
Lucene查询的类型取决于字段类型,对于字符串
字段,其为TermRangeQuery,而对于数字/日期字段,该查询为
a NumericRangeQuery。

Matches documents with fields that have terms within a certain range. The type of the Lucene query depends on the field type, for string fields, the TermRangeQuery, while for number/date fields, the query is a NumericRangeQuery.

gte -大于或等于

lte -小于或等于

gt -大于

lt -小于

https:// www .elastic.co / guide / zh-CN / elasticsearch / reference / current / query-dsl-range-query.html

这篇关于如何查询elasticsearch大于和小于?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆