> For the complete documentation index, see [llms.txt](https://xiaoxiami.gitbook.io/elasticsearch/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://xiaoxiami.gitbook.io/elasticsearch/ji-chu/mapping/323mapping-parametersff08-ying-she-can-shu-ff09/positionincrement-gap-ff08-duan-yu-wei-zhi-jian-xi-ff09.md).

# position\_increment\_gap（短语位置间隙）

被解析的 **text fields**（文本字段）会将 **term**（词根）的位置考虑进去,目的是为了能支持 **proximity queries**（近似查询）和 **phrase queries**（短语查询）。当我们索引一个含有多个值的 **text fields**（文本字段）时，会在各个值之间加入一个"假想"的间隙，这样就可以阻止大多数跨值匹配的短语查询。这个间隙的大小使用 **position\_increment\_gap** 参数来设定,默认值是100。

例如：

```
curl -XPUT 'localhost:9200/my_index/groups/1?pretty' -H 'Content-Type: application/json' -d'
{
    "names": [ "John Abraham", "Lincoln Smith"]
}
'
curl -XGET 'localhost:9200/my_index/groups/_search?pretty' -H 'Content-Type: application/json' -d'
{
    "query": {
        "match_phrase": {
            "names": {
                "query": "Abraham Lincoln" #1
            }
        }
    }
}
'
curl -XGET 'localhost:9200/my_index/groups/_search?pretty' -H 'Content-Type: application/json' -d'
{
    "query": {
        "match_phrase": {
            "names": {
                "query": "Abraham Lincoln",
                "slop": 101 #2
            }
        }
    }
}
'
```

| 1 | 这个短语查询跟我们预期的一样，与这个文档不匹配。                                                                               |
| - | ------------------------------------------------------------------------------------------------------ |
| 2 | 这个短语查询会匹配到文档,因为虽然**Abraham**和**Lincoln** 在不同的**string**（字符串），但**slop**>**position\_increment\_gap**`。` |

**position\_increment\_gap** 可以在映射时设定特定的值。例如：

```
curl -XPUT 'localhost:9200/my_index?pretty' -H 'Content-Type: application/json' -d'
{
  "mappings": {
    "groups": {
      "properties": {
        "names": {
          "type": "text",
          "position_increment_gap": 0 #1
        }
      }
    }
  }
}
'
curl -XPUT 'localhost:9200/my_index/groups/1?pretty' -H 'Content-Type: application/json' -d'
{
    "names": [ "John Abraham", "Lincoln Smith"]
}
'
curl -XGET 'localhost:9200/my_index/groups/_search?pretty' -H 'Content-Type: application/json' -d'
{
    "query": {
        "match_phrase": {
            "names": "Abraham Lincoln" #2
        }
    }
}
'
```

| 1 | 下一个数组中的第一个词根与前一个数组中的最后一个词根的间隙将会是0。  |
| - | ----------------------------------- |
| 2 | 这个短语查询会很奇怪的匹配到我们的文档,但这个就是我们映射时设定的目的 |

> 注意
>
> 同一索引中相同名字的字段可以设定不同的**position\_increment\_gap**值。他的值可以通过[**PUT mapping API**](https://www.elastic.co/guide/en/elasticsearch/reference/5.3/indices-put-mapping.html)使用同名字段来进行更新。
