ElasticSearch: preserve_position_increments not working

Viewed 716

According to the docs

https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-completion.html

preserve_position_increments=false is supposed to make consecutive keywords in a string searchable. But for me it's not working. Is this a bug? Steps to reproduce in Kibana:

PUT /example-index/
{
  "settings": {
    "number_of_shards": 1,
    "number_of_replicas": 0
  },
  "mappings": {
    "_doc": {
      "properties": {
        "example-suggest-field": {
          "type": "completion",
          "analyzer": "stop",
          "preserve_position_increments": false,
          "max_input_length": 50
        }
      }
    }
  }
}

PUT /example-index/_doc/1
{
  "example-suggest-field": [
        {
            "input": "Nevermind Nirvana",
            "weight" : 10
        }
    ]
}

POST /example-index/_search
{
  "suggest": {
    "bib-suggest" : {
        "prefix" : "nir",
        "completion" : {
            "field" : "example-suggest-field"
        }
    }
  }
}

POST /example-index/_search
{
  "suggest": {
    "bib-suggest" : {
        "prefix" : "nev",
        "completion" : {
            "field" : "example-suggest-field"
        }
    }
  }
}

If yes I will make a bug report

1 Answers

It's not a bug, preserve_position_increments is only useful when you are removing stopwords and would like to search for the token coming after the stopword (i.e. search for Beat and find The Beatles).

In your case, you should probably index ["Nevermind", "Nirvana"] instead, i.e. and array of tokens.

If you try to indexing "The Nirvana" instead, you'll find it by searching for nir

Related