position_increment_gap

edit

Analyzed string fields take term positions into account, in order to be able to support proximity or phrase queries. When indexing an array of strings, each string of the array is indexed directly after the previous one, almost as though all the strings in the array had been concatenated into one big string.

This can result in matches from phrase queries spanning two array elements. For instance:

PUT /my_index/groups/1
{
    "names": [ "John Abraham", "Lincoln Smith"]
}

GET /my_index/groups/_search
{
    "query": {
        "match_phrase": {
            "names": "Abraham Lincoln" 
        }
    }
}

This phrase query matches our document, even though Abraham and Lincoln are in separate strings.

The position_increment_gap can introduce a fake gap between each array element. For instance:

PUT my_index
{
  "mappings": {
    "my_type": {
      "properties": {
        "names": {
          "type": "string",
          "position_increment_gap": 50 
        }
      }
    }
  }
}

PUT /my_index/groups/1
{
    "names": [ "John Abraham", "Lincoln Smith"]
}

GET /my_index/groups/_search
{
    "query": {
        "match_phrase": {
            "names": "Abraham Lincoln" 
        }
    }
}

The first term in the next array element will be 50 terms apart from the last term in the previous array element.

The phrase query no longer matches our document.

The position_increment_gap setting is allowed to have different settings for fields of the same name in the same index. Its value can be updated on existing fields using the PUT mapping API.