【问题标题】:Mappings on filed Elastic Search字段 Elasticsearch 上的映射
【发布时间】:2017-10-13 20:48:07
【问题描述】:

我正在使用弹性搜索来自动完成并纠正拼写错误。我的字段有这个映射(用于自动完成)。

    **Mapping:**

      "name": {
                "type": "text",
                "analyzer": "autocomplete"
              }

现在我想在这个字段上实现短语建议。当我使用它时它给出了错误的结果。那是因为我认为现有的映射。

    **POST XYZ/_search**

    {
      "suggest": {
        "text": "ipone 16",
        "simple_phrase": {
          "phrase": {
            "field": "name",
            "highlight": {
              "pre_tag": "<em>",
              "post_tag": "</em>"
            }
          }
        }
      }
    }

    **Results:**
      "options": [
              {
                "text": "i ip ipo iphon iphone 1 16",
                "highlighted": "i ip ipo <em>iphon iphone</em> 1 16",
                "score": 1.6111489e-8
              },
              {
                "text": "i ip ipo iphon iphon 1 16",
                "highlighted": "i ip ipo <em>iphon iphon</em> 1 16",
                "score": 1.4219211e-8
              },
              {
                "text": "i ip ipo ipho iphone 1 16",
                "highlighted": "i ip ipo <em>ipho iphone</em> 1 16",
                "score": 1.3510152e-8
              },
              {
                "text": "i ip ipo ipho iphon 1 16",
                "highlighted": "i ip ipo <em>ipho iphon</em> 1 16",
                "score": 1.1923397e-8
              },
              {
                "text": "i ip ipo iron iphone 1 16",
                "highlighted": "i ip ipo <em>iron iphone</em> 1 16",
                "score": 6.443544e-9
              }
            ]

    **From the document i should use this for phrase suggester.**

    "mappings": {
        "test": {
          "properties": {
            "title": {
              "type": "text",
              "fields": {
                "trigram": {
                  "type": "text",
                  "analyzer": "trigram"
                },
                "reverse": {
                  "type": "text",
                  "analyzer": "reverse"
                }
              }
            }
          }

**How can i use two different mapping on same filed?**

【问题讨论】:

    标签: elasticsearch elasticsearch-5 kibana-5


    【解决方案1】:
    • 由于您的结果未正确标记,问题可能来自 您的 aurocomplete 分析仪。请提供您的 _settings 以查看 为您的分析器定义。

    • name.trigram 进行查询。

    • 解决此问题后,最好使用 collate 修剪您的结果

    【讨论】:

    • 我在一个新的文件上添加了这个设置。如何使用短语提示器来预测拼写错误的单词? “name_suggest”:{“type”:“text”,“fields”:{“reverse”:{“type”:“text”,“analyzer”:“reverse”},“trigram”:{“type”:“ text", "analyzer": "trigram" } } }
    【解决方案2】:

    您可以编写这样的查询。请为此查询提供输出。
    拥有trigram analyzer 设置(tokenizerchar mappers 和 token filters)也很好

    {
       "suggest": {
          "text": "noble prize",
          "simple_phrase": {
             "phrase": {
                "field": "name_suggest.trigram",
                "size": 1,
                "gram_size": 3,
                "direct_generator": [
                   {
                      "field": "name_suggest.trigram",
                      "suggest_mode": "always"
                   }
                ],
                 "collate": {
                   "query": {
                      "inline": {
                         "match": {
                            "title": "{{suggestion}}"
                         }
                      }
                   },
                   "prune": true
                },
                "highlight": {
                   "pre_tag": "<em>",
                   "post_tag": "</em>"
                }
             }
          }
       }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-08-31
      • 2017-05-18
      • 1970-01-01
      • 2016-04-23
      • 1970-01-01
      • 2021-01-27
      • 1970-01-01
      相关资源
      最近更新 更多