MST

星途 面试题库

面试题:ElasticSearch中数字值范围查询API的应用

在ElasticSearch中,假设你有一个包含商品价格(数字类型)的索引,现在需要查询价格在100到200之间(包含100和200)的商品,用ElasticSearch API如何实现?请写出对应的查询语句,并解释相关参数的含义。
45.4万 热度难度
数据库ElasticSearch

知识考点

AI 面试

面试题答案

一键面试
{
    "query": {
        "range": {
            "商品价格字段名": {
                "gte": 100,
                "lte": 200
            }
        }
    }
}
  • range:表示范围查询。
  • 商品价格字段名:需要替换为实际索引中存储商品价格的字段名称。
  • gte:即“greater than or equal to”,表示大于等于,这里指定价格下限为100。
  • lte:即“less than or equal to”,表示小于等于,这里指定价格上限为200。