10

I am new to Elastic search and I am trying to create one demo of Completion suggester with whitespace Analyzer.

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."

I know an easy solution for this is to add multi-field input as :

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

My mapping :

{
  "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
                    }
                }
            }
        }
}

My document :

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

Search request :

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

This search is not returning me the correct output, but if I use prefix = 'hel' I am getting correct output : "Hello elastic search."

In brief I would like to know is whitespace Analyzer works with completion suggester? and if there is a way, can you please suggest me.

PS: I have already look for this links but I didn't find useful answer.

ElasticSearch completion suggester Standard Analyzer not working

What Elasticsearch Analyzer to use for this completion suggester?

I find this link useful Word-oriented completion suggester (ElasticSearch 5.x). However they have not use completion suggester.

Thanks in advance.

Jimmy

4

2 回答 2

5

补全建议器无法执行全文查询,这意味着它无法根据多词字段中间的单词返回建议。

ElasticSearch本身:

原因是 FST 查询与全文查询不同。我们在短语中的任何地方都找不到单词。相反,我们必须从图表的左侧开始并向右移动。

正如您所发现的,可以匹配字段中间的补全建议器的最佳替代方案是边缘 n-gram 过滤器。

于 2019-01-07T18:50:56.217 回答
2

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 建议返回有意义的短语。

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

于 2020-05-19T08:39:13.077 回答