position-increment-gap.asciidoc 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. [[position-increment-gap]]
  2. === `position_increment_gap`
  3. <<mapping-index,Analyzed>> text fields take term <<index-options,positions>>
  4. into account, in order to be able to support
  5. <<query-dsl-match-query-phrase,proximity or phrase queries>>.
  6. When indexing text fields with multiple values a "fake" gap is added between
  7. the values to prevent most phrase queries from matching across the values. The
  8. size of this gap is configured using `position_increment_gap` and defaults to
  9. `100`.
  10. For example:
  11. [source,js]
  12. --------------------------------------------------
  13. PUT my_index/_doc/1
  14. {
  15. "names": [ "John Abraham", "Lincoln Smith"]
  16. }
  17. GET my_index/_search
  18. {
  19. "query": {
  20. "match_phrase": {
  21. "names": {
  22. "query": "Abraham Lincoln" <1>
  23. }
  24. }
  25. }
  26. }
  27. GET my_index/_search
  28. {
  29. "query": {
  30. "match_phrase": {
  31. "names": {
  32. "query": "Abraham Lincoln",
  33. "slop": 101 <2>
  34. }
  35. }
  36. }
  37. }
  38. --------------------------------------------------
  39. // CONSOLE
  40. <1> This phrase query doesn't match our document which is totally expected.
  41. <2> This phrase query matches our document, even though `Abraham` and `Lincoln`
  42. are in separate strings, because `slop` > `position_increment_gap`.
  43. The `position_increment_gap` can be specified in the mapping. For instance:
  44. [source,js]
  45. --------------------------------------------------
  46. PUT my_index
  47. {
  48. "mappings": {
  49. "properties": {
  50. "names": {
  51. "type": "text",
  52. "position_increment_gap": 0 <1>
  53. }
  54. }
  55. }
  56. }
  57. PUT my_index/_doc/1
  58. {
  59. "names": [ "John Abraham", "Lincoln Smith"]
  60. }
  61. GET my_index/_search
  62. {
  63. "query": {
  64. "match_phrase": {
  65. "names": "Abraham Lincoln" <2>
  66. }
  67. }
  68. }
  69. --------------------------------------------------
  70. // CONSOLE
  71. <1> The first term in the next array element will be 0 terms apart from the
  72. last term in the previous array element.
  73. <2> The phrase query matches our document which is weird, but its what we asked
  74. for in the mapping.