【问题标题】:match an indexed phrase with fuzzy in elastic用弹性模糊匹配索引短语
【发布时间】:2021-03-22 12:32:49
【问题描述】:

我在 elasticsearch 中索引了以下 2 个条目:

united states
united states minor outlying islands

我想模糊匹配距离为 1,因此如果我发送以下查询词,我只想匹配 united states

united tsates
unitedstates
united sates

我尝试了其他问题(herehere)中建议的 span_near 方法,但这仍然与 united statesunited states minor outlying islands 匹配。

如何仅将united states 与上述术语列表匹配?

第一次尝试:

{
   "query":{
      "bool":{
         "must":{
            "match":{
               "country_name":{
                  "query":"united tsates",
                  "fuzziness":1,
                  "operator": "and"
               }
            }
         }
      }
   }
}

尝试span_near:

{
   "query":{
      "span_near":{
         "clauses":[
            {
               "span_multi":{
                  "match":{
                     "fuzzy":{
                        "country_name":{
                           "fuzziness":"1",
                           "value":"united"
                        }
                     }
                  }
               }
            },
            {
               "span_multi":{
                  "match":{
                     "fuzzy":{
                        "country_name":{
                           "fuzziness":"1",
                           "value":"tsates"
                        }
                     }
                  }
               }
            }
         ],
         "slop":0,
         "in_order":"true"
      }
   }
}

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    对关键字字段进行模糊查询怎么样?像这样的

    GET test_index/_search
        {
          "query": {
            "fuzzy": {
              "country_name.keyword": "united tsates"
            }
          }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-08
      • 1970-01-01
      • 1970-01-01
      • 2014-08-23
      • 2014-10-22
      • 2012-02-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多