Range query with elasticsearch for string

后端 未结 2 1892
余生分开走
余生分开走 2021-02-11 06:30

I am trying use range query with elasticsearch

{
    \"query\": {
        \"range\": {
             \"order_no\": {
                 \"gte\": \"VM-0001\",
               


        
相关标签:
2条回答
  • 2021-02-11 07:20
    {
      "query": {
        "range": {
          "order_no": {
            "gte": "vm-0001",
            "lte": "vm-0005"
          }
        }
      }
    }
    
    0 讨论(0)
  • 2021-02-11 07:21

    As per the documentation, in case of string fields, Elasticsearch uses a TermRangeQuery which as far as I know doesn't analyze the term to search for. This means that your range VM-0001 - VM-0005 searches for exact these terms. Whereas you have in your index something like vm-0001 (lowercase). So, either use:

    {
      "query": {
        "range": {
          "order_no": {
            "gte": "vm-0001",
            "lte": "vm-0005"
          }
        }
      }
    }
    

    or add another field in your index where you keep the order_no as keyword without any lowercasing or nGram-atization.

    0 讨论(0)
提交回复
热议问题