【问题标题】:Wildcard search issue with long datatype in elasticsearchelasticsearch中长数据类型的通配符搜索问题
【发布时间】:2020-12-02 14:11:50
【问题描述】:
   {
   "from":0,
   "query":{
      "bool":{
         "must":[
            {
               "query_string":{
                  "query":"10*",
                  "lenient":true,
                  "fields":[
                     "phoneNumber"
                  ],
                  "escape":true
               }
            }
         ]
      }
   }
}

这里的 phonenumber 是 long 类型,我们要对其执行通配符搜索。 我将查询传递为 10* ( "query":"10*",) 实际点击数应该是 15,但我的点击数为 0。

如果我对类型为关键字(字符串)地址的字段执行相同的操作,查询 "query":"newyork*", 我会得到结果。

有人知道为什么我们没有得到 long 类型字段的命中吗?

【问题讨论】:

标签: c# elasticsearch nest elasticsearch-5


【解决方案1】:

不能直接对数字数据类型执行通配符。最好将这些整数转换为字符串。

添加一个包含索引数据、映射、搜索查询和搜索结果的工作示例

索引映射:

{
  "mappings": {
    "properties": {
      "phoneNumber": {
        "type": "text"
      }
    }
  }
}

索引数据:

{
  "phoneNumber": "101"
}

搜索查询:

{
  "query": {
    "bool": {
      "filter": [
        {
          "query_string": {
            "query": "10*",
            "fields": [
              "phoneNumber"
            ]
          }
        }
      ]
    }
  }
}

搜索结果:

"hits": [
      {
        "_index": "65109764",
        "_type": "_doc",
        "_id": "1",
        "_score": 0.0,
        "_source": {
          "phoneNumber": "101"
        }
      }
    ]

如果你想进行部分匹配,那么你甚至可以使用edge n-gram tokenizer

【讨论】:

  • @Avinash Kalol 你有机会看我的回答吗,期待得到你的反馈?
  • @AvinashKalol 很高兴这对你有用?你能否请upvote并接受答案?。您可以通过点击我的答案旁边的勾号来接受答案
猜你喜欢
  • 2018-01-17
  • 2018-12-06
  • 2015-03-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多