本文介绍了如何查询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 -小于

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

09-12 18:31