metadata-fields.asciidoc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. [[esql-metadata-fields]]
  2. === {esql} metadata fields
  3. ++++
  4. <titleabbrev>Metadata fields</titleabbrev>
  5. ++++
  6. {esql} can access <<mapping-fields, metadata fields>>.
  7. To access these fields, use the `METADATA` directive with the <<esql-from,`FROM`>> source command. For example:
  8. [source,esql]
  9. ----
  10. FROM index METADATA _index, _id
  11. ----
  12. [[esql-metadata-fields-available]]
  13. ==== Available metadata fields
  14. The following metadata fields are available in {esql}:
  15. [cols="1,1,3"]
  16. |===
  17. |Metadata field |Type |Description
  18. |<<mapping-id-field,`_id`>>
  19. |<<keyword, keyword>>
  20. |Unique document ID.
  21. |<<mapping-ignored-field,`_ignored`>>
  22. |<<keyword, keyword>>
  23. |Names every field in a document that was ignored when the document was indexed.
  24. |<<mapping-index-field,`_index`>>
  25. |<<keyword, keyword>>
  26. |Index name.
  27. |`_index_mode`
  28. |<<keyword, keyword>>
  29. |<<index-mode-setting,Index mode>>. For example: `standard`, `lookup`, or `logsdb`.
  30. |`_score`
  31. |<<number,`float`>>
  32. |Query relevance score (when enabled). Scores are updated when using <<esql-search-functions,full text search functions>>.
  33. |<<mapping-source-field,`_source`>>
  34. |Special `_source` type
  35. |Original JSON document body passed at index time (or a reconstructed version if <<synthetic-source,synthetic `_source`>> is enabled).
  36. |`_version`
  37. |<<number,`long`>>
  38. |Document version number
  39. |===
  40. [[esql-metadata-fields-usage]]
  41. ==== Usage and limitations
  42. - Metadata fields are only available when the data source is an index
  43. - The `_source` type is not supported by functions
  44. - Only the `FROM` command supports the `METADATA` directive
  45. - Once enabled, metadata fields work like regular index fields
  46. [[esql-metadata-fields-examples]]
  47. ==== Examples
  48. [[esql-metadata-fields-examples-basic]]
  49. ===== Basic metadata usage
  50. Once enabled, metadata fields are available to subsequent processing commands, just like other index fields:
  51. [source.merge.styled,esql]
  52. ----
  53. include::{esql-specs}/metadata.csv-spec[tag=multipleIndices]
  54. ----
  55. [%header.monospaced.styled,format=dsv,separator=|]
  56. |===
  57. include::{esql-specs}/metadata.csv-spec[tag=multipleIndices-result]
  58. |===
  59. [[esql-metadata-fields-examples-aggregations]]
  60. ===== Metadata fields and aggregations
  61. Similar to index fields, once an aggregation is performed, a
  62. metadata field will no longer be accessible to subsequent commands, unless
  63. used as a grouping field:
  64. [source.merge.styled,esql]
  65. ----
  66. include::{esql-specs}/metadata.csv-spec[tag=metaIndexInAggs]
  67. ----
  68. [%header.monospaced.styled,format=dsv,separator=|]
  69. |===
  70. include::{esql-specs}/metadata.csv-spec[tag=metaIndexInAggs-result]
  71. |===
  72. [[esql-metadata-fields-examples-score]]
  73. ===== Sort results by search score
  74. [source,esql]
  75. ----
  76. FROM products METADATA _score
  77. | WHERE MATCH(description, "wireless headphones")
  78. | SORT _score DESC
  79. | KEEP name, description, _score
  80. ----
  81. [TIP]
  82. ====
  83. Refer to <<esql-for-search>> for more information on relevance scoring and how to use `_score` in your queries.
  84. ====