简体   繁体   English

范围与elasticsearch

[英]Range with elasticsearch

I am trying search with elasticsearch with range query. 我正在尝试使用Elasticsearch与范围查询进行搜索。 (PHP) (PHP)

This is my source code 这是我的源代码

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

= =

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

But in result it have order_no: 但结果是它具有order_no:

2000
2001
2000001
200000
....

I want show only 我只想显示

2000
2001

This field have mapping: 该字段具有映射:

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

How can fix it? 如何解决?

The best and most effective way is to change your field mapping to 最好和最有效的方法是将字段映射更改为

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

String range queries are very slow compared to numeric range ones. 与数字范围查询相比,字符串范围查询的速度非常慢。

If you are constrained from changing the field mapping then another option is to pad the input values with zeros while indexing as well as searching as 如果您不能更改字段映射,那么另一种选择是在索引以及搜索时以零填充输入值。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM