Delimited payload token filter

The older name delimited_payload_filter is deprecated and should not be used with new indices. Use delimited_payload instead.

Separates a token stream into tokens and payloads based on a specified delimiter.

For example, you can use the delimited_payload filter with a | delimiter to split the|1 quick|2 fox|3 into the tokens the, quick, and fox with respective payloads of 1, 2, and 3.

This filter uses Lucene’s DelimitedPayloadTokenFilter.

Payloads

A payload is user-defined binary data associated with a token position and stored as base64-encoded bytes.

Elasticsearch does not store token payloads by default. To store payloads, you must:

  • Set the term_vector mapping parameter to with_positions_payloads or with_positions_offsets_payloads for any field storing payloads.
  • Use an index analyzer that includes the delimited_payload filter

You can view stored payloads using the term vectors API.

Example

The following analyze API request uses the delimited_payload filter with the default | delimiter to split the|0 brown|10 fox|5 is|0 quick|10 into tokens and payloads.

  1. GET _analyze
  2. {
  3. "tokenizer": "whitespace",
  4. "filter": ["delimited_payload"],
  5. "text": "the|0 brown|10 fox|5 is|0 quick|10"
  6. }

The filter produces the following tokens:

  1. [ the, brown, fox, is, quick ]

Note that the analyze API does not return stored payloads. For an example that includes returned payloads, see Return stored payloads.

Add to an analyzer

The following create index API request uses the delimited-payload filter to configure a new custom analyzer.

  1. PUT delimited_payload
  2. {
  3. "settings": {
  4. "analysis": {
  5. "analyzer": {
  6. "whitespace_delimited_payload": {
  7. "tokenizer": "whitespace",
  8. "filter": [ "delimited_payload" ]
  9. }
  10. }
  11. }
  12. }
  13. }

Configurable parameters

delimiter

(Optional, string) Character used to separate tokens from payloads. Defaults to |.

encoding

(Optional, string) Data type for the stored payload. Valid values are:

  • float

    (Default) Float

    identity

    Characters

    int

    Integer

Customize and add to an analyzer

To customize the delimited_payload filter, duplicate it to create the basis for a new custom token filter. You can modify the filter using its configurable parameters.

For example, the following create index API request uses a custom delimited_payload filter to configure a new custom analyzer. The custom delimited_payload filter uses the + delimiter to separate tokens from payloads. Payloads are encoded as integers.

  1. PUT delimited_payload_example
  2. {
  3. "settings": {
  4. "analysis": {
  5. "analyzer": {
  6. "whitespace_plus_delimited": {
  7. "tokenizer": "whitespace",
  8. "filter": [ "plus_delimited" ]
  9. }
  10. },
  11. "filter": {
  12. "plus_delimited": {
  13. "type": "delimited_payload",
  14. "delimiter": "+",
  15. "encoding": "int"
  16. }
  17. }
  18. }
  19. }
  20. }

Return stored payloads

Use the create index API to create an index that:

  • Includes a field that stores term vectors with payloads.
  • Uses a custom index analyzer with the delimited_payload filter.
  1. PUT text_payloads
  2. {
  3. "mappings": {
  4. "properties": {
  5. "text": {
  6. "type": "text",
  7. "term_vector": "with_positions_payloads",
  8. "analyzer": "payload_delimiter"
  9. }
  10. }
  11. },
  12. "settings": {
  13. "analysis": {
  14. "analyzer": {
  15. "payload_delimiter": {
  16. "tokenizer": "whitespace",
  17. "filter": [ "delimited_payload" ]
  18. }
  19. }
  20. }
  21. }
  22. }

Add a document containing payloads to the index.

  1. POST text_payloads/_doc/1
  2. {
  3. "text": "the|0 brown|3 fox|4 is|0 quick|10"
  4. }

Use the term vectors API to return the document’s tokens and base64-encoded payloads.

  1. GET text_payloads/_termvectors/1
  2. {
  3. "fields": [ "text" ],
  4. "payloads": true
  5. }

The API returns the following response:

  1. {
  2. "_index": "text_payloads",
  3. "_type": "_doc",
  4. "_id": "1",
  5. "_version": 1,
  6. "found": true,
  7. "took": 8,
  8. "term_vectors": {
  9. "text": {
  10. "field_statistics": {
  11. "sum_doc_freq": 5,
  12. "doc_count": 1,
  13. "sum_ttf": 5
  14. },
  15. "terms": {
  16. "brown": {
  17. "term_freq": 1,
  18. "tokens": [
  19. {
  20. "position": 1,
  21. "payload": "QEAAAA=="
  22. }
  23. ]
  24. },
  25. "fox": {
  26. "term_freq": 1,
  27. "tokens": [
  28. {
  29. "position": 2,
  30. "payload": "QIAAAA=="
  31. }
  32. ]
  33. },
  34. "is": {
  35. "term_freq": 1,
  36. "tokens": [
  37. {
  38. "position": 3,
  39. "payload": "AAAAAA=="
  40. }
  41. ]
  42. },
  43. "quick": {
  44. "term_freq": 1,
  45. "tokens": [
  46. {
  47. "position": 4,
  48. "payload": "QSAAAA=="
  49. }
  50. ]
  51. },
  52. "the": {
  53. "term_freq": 1,
  54. "tokens": [
  55. {
  56. "position": 0,
  57. "payload": "AAAAAA=="
  58. }
  59. ]
  60. }
  61. }
  62. }
  63. }
  64. }