【问题标题】:ElasticSearch completion suggester Standard Analyzer not workingElasticSearch 完成建议器标准分析器不起作用
【发布时间】:2018-01-13 03:44:19
【问题描述】:

我们正在使用 ElasticSearch completion suggesterStandard Analyzer,但似乎文本没有被标记。

例如

文本:“第一个示例”、“第二个示例”

搜索:“Fi”返回“第一个示例”

虽然

搜索:“Ex”不返回任何结果返回“First Example”

【问题讨论】:

    标签: elasticsearch autocomplete autosuggest


    【解决方案1】:

    作为 Elastic 关于完成建议的文档:Completion Suggester

    补全提示器就是所谓的前缀提示器。

    因此,当您发送关键字时,它会查找您的文本的前缀。

    例如:

    搜索:“Fi”=>“第一个示例”

    搜索:“秒”=>“第二个例子”

    但如果你给 Elastic “Ex”,它不会返回任何内容,因为它找不到以“Ex”开头的文本。

    您可以尝试其他一些建议,例如:Term Suggester

    【讨论】:

    • 那么为什么你可以选择不同的分析仪?
    • 是的,我同意 Guy Koraland 的评论。那我们为什么要选择不同的分析器呢?
    【解决方案2】:

    一个很好的解决方法是自己标记字符串并将其放在单独的标记字段中。 然后,您可以在建议查询中使用 2 条建议来搜索这两个字段。

    示例:

    PUT /example
    {
        "mappings": {
            "doc": {
                "properties": {
                    "full": {
                        "type": "completion"
                    },
                    "tokens": {
                        "type": "completion"
                    }
                }
            }
        }
    }
    
    POST /example/doc/_bulk
    { "index":{} }
    {"full": {"input": "First Example"}, "tokens": {"input": ["First", "Example"]}}
    { "index":{} }
    {"full": {"input": "Second Example"}, "tokens": {"input": ["Second", "Example"]}}
    
    POST /example/_search
    {
        "suggest": {
            "full-suggestion": {
                "prefix" : "Ex", 
                "completion" : { 
                    "field" : "full",
                    "fuzzy": true
                }
            },
            "token-suggestion": {
                "prefix": "Ex",
                "completion" : { 
                    "field" : "tokens",
                    "fuzzy": true
                }
            }
        }
    }
    

    搜索结果:

    {
      "took": 1,
      "timed_out": false,
      "_shards": {
        "total": 5,
        "successful": 5,
        "skipped": 0,
        "failed": 0
      },
      "hits": {
        "total": 0,
        "max_score": 0,
        "hits": []
      },
      "suggest": {
        "full-suggestion": [
          {
            "text": "Ex",
            "offset": 0,
            "length": 2,
            "options": []
          }
        ],
        "token-suggestion": [
          {
            "text": "Ex",
            "offset": 0,
            "length": 2,
            "options": [
              {
                "text": "Example",
                "_index": "example",
                "_type": "doc",
                "_id": "Ikvk62ABd4o_n4U8G5yF",
                "_score": 2,
                "_source": {
                  "full": {
                    "input": "First Example"
                  },
                  "tokens": {
                    "input": [
                      "First",
                      "Example"
                    ]
                  }
                }
              },
              {
                "text": "Example",
                "_index": "example",
                "_type": "doc",
                "_id": "I0vk62ABd4o_n4U8G5yF",
                "_score": 2,
                "_source": {
                  "full": {
                    "input": "Second Example"
                  },
                  "tokens": {
                    "input": [
                      "Second",
                      "Example"
                    ]
                  }
                }
              }
            ]
          }
        ]
      }
    }
    

    【讨论】:

    • 手动分词非常重要。您需要生成带状疱疹(word-grams)以避免在您开始在句子中键入第二个单词时搜索返回 0 结果。如果您输入了 3 个单词,例如“第一个示例代码”,那么您将无法返回“Example co”的任何结果,而不会出现整个短语的带状疱疹。
    猜你喜欢
    • 2018-06-26
    • 2022-01-22
    • 1970-01-01
    • 2020-07-14
    • 2023-03-12
    • 1970-01-01
    • 2023-04-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多