使用带有弹性搜索字符串的范围查询 [英] Range query with elasticsearch for string

查看:107
本文介绍了使用带有弹性搜索字符串的范围查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用带有弹性搜索的范围查询

  {
query:{
范围:{
order_no:{
gte:VM-0001,
lte:VM-0005
}
}
}
}

但是弹性返回没有结果。我发现系统有字符串的问题包括 - _



这是该字段的映射:

 order_no:{
type:string
index_analyzer:str_index_analyzer,
search_analyzer:str_search_analyzer
}






  {
分析:{
analyzer:{
str_search_analyzer:{
tokenizer:keyword,
filter:[
smallcase
]
},
str_index_analyzer :{
tokenizer:keyword,
filter:[
smallcase,
substring
]
}
},
filter:{
substring:{
type:nGram,
min_gram:1,
max_gram:20
}
}
}
}


解决方案

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


I am trying use range query with elasticsearch

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

But elastic return no result. I found system have problem with string include - or _

This is mapping of that field:

"order_no" : {
      "type" : "string",
      "index_analyzer" : "str_index_analyzer",
      "search_analyzer" : "str_search_analyzer"
}


{
  "analysis": {
    "analyzer": {
      "str_search_analyzer": {
        "tokenizer": "keyword",
        "filter": [
          "lowercase"
        ]
      },
      "str_index_analyzer": {
        "tokenizer": "keyword",
        "filter": [
          "lowercase",
          "substring"
        ]
      }
    },
    "filter": {
      "substring": {
        "type": "nGram",
        "min_gram": 1,
        "max_gram": 20
      }
    }
  }
}

解决方案

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

这篇关于使用带有弹性搜索字符串的范围查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆