elasticsearchautocompleteautosuggestelasticsearch-analyzerselasticsearch-6

Elasticsearch : Completion suggester not working with whitespace Analyzer


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


Solution

  • The completion suggester cannot perform full-text queries, which means that it cannot return suggestions based on words in the middle of a multi-word field.

    From ElasticSearch itself:

    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.

    As you discovered, the best alternative to the completion suggester that can match the middle of fields is an edge n-gram filter.