position_increment_gap
编辑position_increment_gap
编辑
已分析 文本字段会考虑词语的 位置,以便支持 邻近度或短语查询。在对具有多个值的文本字段进行索引时,会在值之间添加一个“虚拟”间隙,以防止大多数短语查询跨越值进行匹配。此间隙的大小使用 position_increment_gap
配置,默认值为 100
。
例如
response = client.index( index: 'my-index-000001', id: 1, body: { names: [ 'John Abraham', 'Lincoln Smith' ] } ) puts response response = client.search( index: 'my-index-000001', body: { query: { match_phrase: { names: { query: 'Abraham Lincoln' } } } } ) puts response response = client.search( index: 'my-index-000001', body: { query: { match_phrase: { names: { query: 'Abraham Lincoln', slop: 101 } } } } ) puts response
PUT my-index-000001/_doc/1 { "names": [ "John Abraham", "Lincoln Smith"] } GET my-index-000001/_search { "query": { "match_phrase": { "names": { "query": "Abraham Lincoln" } } } } GET my-index-000001/_search { "query": { "match_phrase": { "names": { "query": "Abraham Lincoln", "slop": 101 } } } }
此短语查询不会匹配我们的文档,这是完全预期的。 |
|
此短语查询匹配我们的文档,即使 |
可以在映射中指定 position_increment_gap
。例如
response = client.indices.create( index: 'my-index-000001', body: { mappings: { properties: { names: { type: 'text', position_increment_gap: 0 } } } } ) puts response response = client.index( index: 'my-index-000001', id: 1, body: { names: [ 'John Abraham', 'Lincoln Smith' ] } ) puts response response = client.search( index: 'my-index-000001', body: { query: { match_phrase: { names: 'Abraham Lincoln' } } } ) puts response