Elasticsearch模糊查询字符串与模糊匹配。

27

我们有一个项目索引,我正在尝试对项目名称进行模糊通配符查询。

查询如下:

{
  "from": 0,
  "size": 10,
  "query": {
    "bool": {
      "must": {
        "query_string": {
          "fields": [
            "name.suggest"
          ],
          "query": "avacado*",
          "fuzziness": 0.7
        }
      }
    }
  }
}

索引中的字段以及正在使用的分析器。

suggest_analyzer":{
    "type": "custom",
    "tokenizer": "standard",
    "filter": ["standard", "lowercase", "shingle", "punctuation"]
  }


"punctuation" : {
    "type" : "word_delimiter",
    "preserve_original": "true"
  }



"name": {
    "fields": {
      "name": {
        "type": "string",
        "analyzer": "stem"
      },
      "suggest":{ 
        "type": "string", 
        "analyzer": "suggest_analyzer"
      },
      "untouched": {
        "include_in_all": false,
        "index": "not_analyzed",
        "index_options": "docs",
        "omit_norms": true,
        "type": "string"
      },
      "untouched_lowercase": {
        "type": "string", 
        "index_analyzer": "lowercase",
        "search_analyzer": "lowercase"
      }
    },
    "type": "multi_field"
  },

问题如下:

一个名为“Avocado Test”的项目将匹配以下内容:

  • avocado*
  • avo*
  • avacado

但无法匹配以下内容:

  • avacado*
  • ava*
  • ava~2

我似乎无法让模糊搜索与通配符一起使用,似乎要么只能使用模糊搜索,要么只能使用通配符,无法同时使用。

ES版本为1.3.1

请注意,我的查询已经简化了,我们还有其他过滤操作,但为了消除结果中的任何歧义,我将其简化为仅查询。我尝试使用建议功能,但它们不允许我们需要的过滤级别。

是否有其他方法来处理建议/自动完成样式搜索并使用模糊搜索以捕获拼写错误?


1
看起来你需要的是“模糊自动完成”,你可以通过completion suggester来实现。 - keety
这个回答对你有帮助吗?(链接为:https://dev59.com/H4nda4cB1Zd3GeqPEtYE#29723235) - Sloan Ahrens
@keety 如果我们不需要进行任何过滤,完成建议器会很有帮助。目前每个用户在输入提示时都会得到索引中一特定子集的文档,这些文档是通过元标记系统和其他过滤器对其进行筛选的。此外,我们还有规则规定项目不能具有标签 x,因此我们必须进行否定操作,而目前的条件还不允许。 - dstarh
@SloanAhrens 看起来很有希望。我会在周一试试看。 - dstarh
3
对于其他需要帮助的人,请访问https://dev59.com/H4nda4cB1Zd3GeqPEtYE#29723235,该链接对我非常有用。 - dstarh
显示剩余2条评论
1个回答

0
你可以尝试使用EdgeNgramTokenFilter,将其应用于所需字段上的分析器,并对其进行模糊搜索。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接