本文介绍了弹性搜索的映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用弹性搜索来进行自动填充,也可以纠正拼写错误。我有这个字段的映射(用于自动完成)。

I am using elastic search for autocompletion and also to correct spelling mistakes.I have this mapping for my field(for auto-completion).

    **Mapping:**

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

现在我想在这个字段上实现短语suggester。当我使用它是错误的结果。因为我现在的映射。

Now i want to implement phrase suggester on this field.When i use this it is giving wrong result.Thats because of existing mapping i think.

    **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?**


推荐答案

你可以写一个这样的查询,请提供这个查询的输出。

还有你的 trigram分析器设置( tokenizer , char mapper 和令牌过滤器 s)

You can write a query like this. Please provide output for this query.
It's also good to have your trigram analyzer settings (tokenizer, char mappers and 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>"
            }
         }
      }
   }
}

这篇关于弹性搜索的映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-18 08:00