index_options

index_options

The index_options parameter controls what information is added to the inverted index for search and highlighting purposes. Only term-based field types like text and keyword support this configuration.

The parameter accepts one of the following values. Each value retrieves information from the previous listed values. For example, freqs contains docs; positions contains both freqs and docs.

docs

Only the doc number is indexed. Can answer the question Does this term exist in this field?

freqs

Doc number and term frequencies are indexed. Term frequencies are used to score repeated terms higher than single terms.

positions (default)

Doc number, term frequencies, and term positions (or order) are indexed. Positions can be used for proximity or phrase queries.

offsets

Doc number, term frequencies, positions, and start and end character offsets (which map the term back to the original string) are indexed. Offsets are used by the unified highlighter to speed up highlighting.

  1. resp = client.indices.create(
  2. index="my-index-000001",
  3. mappings={
  4. "properties": {
  5. "text": {
  6. "type": "text",
  7. "index_options": "offsets"
  8. }
  9. }
  10. },
  11. )
  12. print(resp)
  13. resp1 = client.index(
  14. index="my-index-000001",
  15. id="1",
  16. document={
  17. "text": "Quick brown fox"
  18. },
  19. )
  20. print(resp1)
  21. resp2 = client.search(
  22. index="my-index-000001",
  23. query={
  24. "match": {
  25. "text": "brown fox"
  26. }
  27. },
  28. highlight={
  29. "fields": {
  30. "text": {}
  31. }
  32. },
  33. )
  34. print(resp2)
  1. response = client.indices.create(
  2. index: 'my-index-000001',
  3. body: {
  4. mappings: {
  5. properties: {
  6. text: {
  7. type: 'text',
  8. index_options: 'offsets'
  9. }
  10. }
  11. }
  12. }
  13. )
  14. puts response
  15. response = client.index(
  16. index: 'my-index-000001',
  17. id: 1,
  18. body: {
  19. text: 'Quick brown fox'
  20. }
  21. )
  22. puts response
  23. response = client.search(
  24. index: 'my-index-000001',
  25. body: {
  26. query: {
  27. match: {
  28. text: 'brown fox'
  29. }
  30. },
  31. highlight: {
  32. fields: {
  33. text: {}
  34. }
  35. }
  36. }
  37. )
  38. puts response
  1. const response = await client.indices.create({
  2. index: "my-index-000001",
  3. mappings: {
  4. properties: {
  5. text: {
  6. type: "text",
  7. index_options: "offsets",
  8. },
  9. },
  10. },
  11. });
  12. console.log(response);
  13. const response1 = await client.index({
  14. index: "my-index-000001",
  15. id: 1,
  16. document: {
  17. text: "Quick brown fox",
  18. },
  19. });
  20. console.log(response1);
  21. const response2 = await client.search({
  22. index: "my-index-000001",
  23. query: {
  24. match: {
  25. text: "brown fox",
  26. },
  27. },
  28. highlight: {
  29. fields: {
  30. text: {},
  31. },
  32. },
  33. });
  34. console.log(response2);
  1. PUT my-index-000001
  2. {
  3. "mappings": {
  4. "properties": {
  5. "text": {
  6. "type": "text",
  7. "index_options": "offsets"
  8. }
  9. }
  10. }
  11. }
  12. PUT my-index-000001/_doc/1
  13. {
  14. "text": "Quick brown fox"
  15. }
  16. GET my-index-000001/_search
  17. {
  18. "query": {
  19. "match": {
  20. "text": "brown fox"
  21. }
  22. },
  23. "highlight": {
  24. "fields": {
  25. "text": {}
  26. }
  27. }
  28. }

The text field will use the postings for the highlighting by default because offsets are indexed.