position-offset-gap.asciidoc 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. [[position-offset-gap]]
  2. === `position_offset_gap`
  3. <<mapping-index,Analyzed>> string 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 an array of strings, each string of the array is indexed
  7. directly after the previous one, almost as though all the strings in the array
  8. had been concatenated into one big string.
  9. This can result in matches from phrase queries spanning two array elements.
  10. For instance:
  11. [source,js]
  12. --------------------------------------------------
  13. PUT /my_index/groups/1
  14. {
  15. "names": [ "John Abraham", "Lincoln Smith"]
  16. }
  17. GET /my_index/groups/_search
  18. {
  19. "query": {
  20. "match_phrase": {
  21. "names": "Abraham Lincoln" <1>
  22. }
  23. }
  24. }
  25. --------------------------------------------------
  26. // AUTOSENSE
  27. <1> This phrase query matches our document, even though `Abraham` and `Lincoln` are in separate strings.
  28. The `position_offset_gap` can introduce a fake gap between each array element. For instance:
  29. [source,js]
  30. --------------------------------------------------
  31. PUT my_index
  32. {
  33. "mappings": {
  34. "my_type": {
  35. "properties": {
  36. "names": {
  37. "type": "string",
  38. "position_offset_gap": 50 <1>
  39. }
  40. }
  41. }
  42. }
  43. }
  44. PUT /my_index/groups/1
  45. {
  46. "names": [ "John Abraham", "Lincoln Smith"]
  47. }
  48. GET /my_index/groups/_search
  49. {
  50. "query": {
  51. "match_phrase": {
  52. "names": "Abraham Lincoln" <2>
  53. }
  54. }
  55. }
  56. --------------------------------------------------
  57. // AUTOSENSE
  58. <1> The first term in the next array element will be 50 terms apart from the
  59. last term in the previous array element.
  60. <2> The phrase query no longer matches our document.
  61. TIP: The `position_offset_gap` setting is allowed to have different settings
  62. for fields of the same name in the same index. Its value can be updated on
  63. existing fields using the <<indices-put-mapping,PUT mapping API>>.