【问题标题】:issue with edge_ngram tokenizer IN Elastic search弹性搜索中 edge_ngram 标记器的问题
【发布时间】:2016-12-18 08:54:06
【问题描述】:

我正在使用边缘 ngram 标记器来提供部分匹配。 我的文件看起来像

Name
Labson series LTD 2014
Labson PLO LTD 2014A
Labson PLO LTD 2014-I
Labson PLO LTD. 2014-II

我的映射如下

PUT my_index
{
  "settings": {
    "analysis": {
      "analyzer": {
        "autocomplete": {
          "tokenizer": "autocomplete",
          "filter": [
            "lowercase"
          ]
        },
        "autocomplete_search": {
          "tokenizer": "lowercase"
        }
      },
      "tokenizer": {
        "autocomplete": {
          "type": "edge_ngram",
          "min_gram": 2,
          "max_gram": 40,
          "token_chars": [
            "letter",
            "digit"
          ]
        }
      }
    }
  },
  "mappings": {
    "doc": {
      "properties": {
        "title": {
          "type": "string",
          "analyzer": "autocomplete",
          "search_analyzer": "autocomplete_search"
        }
      }
    }
  }
}

PUT my_index/doc/1
{
  "title": "Labson Series LTD 2014" 
}

PUT my_index/doc/2
{
  "title": "Labson PLO LTD 2014A" 
}


PUT my_index/doc/3
{
  "title": "Labson PLO LTD 2014-I" 
}


PUT my_index/doc/4
{
  "title": "Labson PLO LTD. 2014-II" 
}

以下查询为我提供了 3 个正确的文档(Labson PLO LTD 2014ALabson PLO LTD 2014-ILabson PLO LTD. 2014-II

GET my_index/_search
{
  "query": {
    "match": {
      "title": {
        "query": "labson plo", 
        "operator": "and"
      }
    }
  }
}

但是当我输入 Labson PLO 2014A 时,它给了我 0 个文档

GET my_index/_search
{
  "query": {
    "match": {
      "title": {
        "query": "Labson PLO 2014A", 
        "operator": "and"
      }
    }
  }
}

我希望这会返回 1 个文档 Labson PLO LTD 2014A,但由于某种原因,它似乎没有索引令牌中的数字。如果我在这里遗漏了什么,请告诉我。

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    在您的autocomplete_search 中,您正在使用lowercase 令牌。 它同时执行Letter TokenizerLower Case Token Filter 的功能。

    https://www.elastic.co/guide/en/elasticsearch/reference/2.3//analysis-lowercase-tokenizer.html

    现在让我们看看Letter Tokenizer 做了什么。

    只要遇到不是字母的字符,字母标记器就会将文本分解为术语。

    https://www.elastic.co/guide/en/elasticsearch/reference/master/analysis-letter-tokenizer.html

    所以当你查询时。

    “查询”:“Labson PLO 2014A”,

    查询实际上变成了

    "+title:labson +title:plo +title:a"

    自从字母标记器于 2014 年下降以来。现在您的索引标记不包含仅包含字母 a 的标记。这就是为什么你没有得到任何结果。

    您可以在 kibana 中像这样分析您的查询

    POST my_index/_validate/query?explain
    {
      "query": {
        "match": {
          "title": {
            "query": "Labson PLO 2014a", 
            "operator": "and"
          }
        }
      }
    }
    

    你会看到 2014 年正在下降。来自最终查询。

    还可以使用以下查询查看字母标记器产生的内容

    POST _analyze
    {
      "tokenizer": "letter",
      "text": "Labson PLO LTD 2014a"
    }
    

    【讨论】:

      猜你喜欢
      • 2021-06-22
      • 1970-01-01
      • 1970-01-01
      • 2023-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多