metadata-fields.asciidoc 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. [[esql-metadata-fields]]
  2. == {esql} metadata fields
  3. ++++
  4. <titleabbrev>Metadata fields</titleabbrev>
  5. ++++
  6. {esql} can access <<mapping-fields, metadata fields>>. The currently
  7. supported ones are:
  8. * <<mapping-index-field,`_index`>>: the index to which the document belongs.
  9. The field is of the type <<keyword, keyword>>.
  10. * <<mapping-id-field,`_id`>>: the source document's ID. The field is of the
  11. type <<keyword, keyword>>.
  12. * `_version`: the source document's version. The field is of the type
  13. <<number,long>>.
  14. To enable the access to these fields, the <<esql-from,`FROM`>> source command needs
  15. to be provided with a dedicated directive:
  16. [source,esql]
  17. ----
  18. FROM index [METADATA _index, _id]
  19. ----
  20. Metadata fields are only available if the source of the data is an index.
  21. Consequently, `FROM` is the only source commands that supports the `METADATA`
  22. directive.
  23. Once enabled, the fields are then available to subsequent processing commands, just
  24. like the other index fields:
  25. [source.merge.styled,esql]
  26. ----
  27. include::{esql-specs}/metadata-ignoreCsvTests.csv-spec[tag=multipleIndices]
  28. ----
  29. [%header.monospaced.styled,format=dsv,separator=|]
  30. |===
  31. include::{esql-specs}/metadata-ignoreCsvTests.csv-spec[tag=multipleIndices-result]
  32. |===
  33. Also, similar to the index fields, once an aggregation is performed, a
  34. metadata field will no longer be accessible to subsequent commands, unless
  35. used as grouping field:
  36. [source.merge.styled,esql]
  37. ----
  38. include::{esql-specs}/metadata-ignoreCsvTests.csv-spec[tag=metaIndexInAggs]
  39. ----
  40. [%header.monospaced.styled,format=dsv,separator=|]
  41. |===
  42. include::{esql-specs}/metadata-ignoreCsvTests.csv-spec[tag=metaIndexInAggs-result]
  43. |===