Elasticsearch:完成建议器不适用于空白分析器

Elasticsearch : Completion suggester not working with whitespace Analyzer

我是 Elastic search 的新手,我正在尝试使用 whitespace Analyzer 创建一个 Completion suggester 的演示。

As per the documentation of Whitespace Analyzer, It breaks text into terms whenever it encounters a whitespace character. So my question is do it works with Completion suggester too?

So for my completion suggester prefix : "ela", I am expecting output as "Hello elastic search."

我知道一个简单的解决方案是将多字段输入添加为:

"suggest": {
         "input": ["Hello","elastic","search"]
 }

However, if this is the solution then what is meaning of using analyzer? Does analyzer make sense in completion suggester?

我的映射:

{
  "settings": {
    "analysis": {
      "analyzer": {
        "completion_analyzer": {
          "type": "custom",
          "filter": [
            "lowercase"
          ],
          "tokenizer": "whitespace"
        }
      }
    }
  },
  "mappings": {
            "my-type": {
                "properties": {
                    "mytext": {
                        "type": "text",
                        "fields": {
                            "keyword": {
                                "type": "keyword",
                                "ignore_above": 256
                            }
                        }
                    },
                    "suggest": {
                        "type": "completion",
                        "analyzer": "completion_analyzer",
                        "search_analyzer": "completion_analyzer",
                        "max_input_length": 50
                    }
                }
            }
        }
}

我的文档:

{
    "_index": "my-index",
    "_type": "my-type",
    "_id": "KTWJBGEBQk_Zl_sQdo9N",
    "_score": 1,
    "_source": {
        "mytext": "dummy text",
        "suggest": {
                 "input": "Hello elastic search."
        }
    }
}

搜索请求:

{
    "suggest": {
        "test-suggest" : {
        "prefix" :"ela", 
        "completion" : { 
            "field" : "suggest",
            "skip_duplicates": true
        }
        }
    }
}

此搜索没有返回正确的输出,但如果我使用 prefix = 'hel' 我得到正确的输出:"Hello elastic search."

简而言之,我想知道 whitespace Analyzer 是否与 completion suggester 一起工作? 如果有办法,请您推荐一下。

PS:我已经在寻找这个 link,但没有找到有用的答案。

ElasticSearch completion suggester Standard Analyzer not working

What Elasticsearch Analyzer to use for this completion suggester?

我发现这个 link 很有用 。但是他们没有使用完成建议器。

提前致谢。

吉米

完成建议器无法执行全文查询,这意味着它无法 return 基于多词字段中间词的建议。

来自 ElasticSearch 本身:

The reason is that an FST query is not the same as a full text query. We can't find words anywhere within a phrase. Instead, we have to start at the left of the graph and move towards the right.

如您所见,可以 匹配字段中间的完成建议器的最佳替代方法是边缘 n-gram 过滤器。

g我知道这个问题由来已久,但您是否尝试过多种建议,一种基于前缀,另一种基于正则表达式?

类似

{
    "suggest": {
        "test-suggest-exact" : {
            "prefix" :"ela", 
            "completion" : { 
                "field" : "suggest",
                "skip_duplicates": true
            }
        },
        "test-suggest-regex" : {
            "regex" :".*ela.*", 
            "completion" : { 
                "field" : "suggest",
                "skip_duplicates": true
            }
        }
    }
}

当第一个为空时,使用第二个建议的结果。好消息是 Elasticsearch 建议返回有意义的短语。

基于 Shingle 的方法,使用完整的查询搜索,然后根据搜索词进行聚合,有时会给出上下文错误的断句。如果你有兴趣,我可以写更多。