具有弹性搜索的范围


Range with elasticsearch

>我正在尝试使用带有范围查询的弹性搜索进行搜索。(菲律宾比索)

这是我的源代码

$searchParams['body']['query']['range']['order_no']['gte'] = "2000";
$searchParams['body']['query']['range']['order_no']['lte'] = "2001";

=

{
    "query": {
        "range": {
             "order_no": {
                 "gte": 2000,
                 "lte": 2001
             }
         }
    }
}

但结果它order_no:

2000
2001
2000001
200000
....

我只想显示

2000
2001

此字段具有映射:

"order_no" : {
    "type" : "string",
     "index" : "not_analyzed"
}

如何解决?

最好和最有效的方法是将字段映射更改为

{
  "order_no": {
    "type": "integer",
    "index": "not_analyzed"
  }
}

与数字范围查询相比,字符串范围查询非常慢。

如果您无法更改字段映射,那么另一种选择是在索引和搜索时用零填充输入值

{
  "query": {
    "range": {
      "order_no": {
        "gte": 00002000,
        "lte": 00002001
      }
    }
  }
}