Skip to content

Commit c27773c

Browse files
authored
[DOCS][8.x] Update ESQL metadata fields page (#129996)
1 parent f922b8e commit c27773c

File tree

1 file changed

+72
-23
lines changed

1 file changed

+72
-23
lines changed
Lines changed: 72 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,71 @@
11
[[esql-metadata-fields]]
22
=== {esql} metadata fields
3-
43
++++
54
<titleabbrev>Metadata fields</titleabbrev>
65
++++
76

8-
{esql} can access <<mapping-fields, metadata fields>>. The currently
9-
supported ones are:
7+
{esql} can access <<mapping-fields, metadata fields>>.
108

11-
* <<mapping-index-field,`_index`>>: the index to which the document belongs.
12-
The field is of the type <<keyword, keyword>>.
9+
To access these fields, use the `METADATA` directive with the <<esql-from,`FROM`>> source command. For example:
1310

14-
* <<mapping-id-field,`_id`>>: the source document's ID. The field is of the
15-
type <<keyword, keyword>>.
11+
[source,esql]
12+
----
13+
FROM index METADATA _index, _id
14+
----
1615

17-
* `_version`: the source document's version. The field is of the type
18-
<<number,long>>.
16+
[[esql-metadata-fields-available]]
17+
==== Available metadata fields
1918

20-
* <<mapping-ignored-field,`_ignored`>>: the ignored source document fields. The field is of the type
21-
<<keyword,keyword>>.
19+
The following metadata fields are available in {esql}:
2220

23-
* `_score`: when enabled, the final score assigned to each row matching an ES|QL query. Scoring will be updated when using <<esql-search-functions,full text search functions>>.
21+
[cols="1,1,3"]
22+
|===
23+
|Metadata field |Type |Description
2424

25-
To enable the access to these fields, the <<esql-from,`FROM`>> source command needs
26-
to be provided with a dedicated directive:
25+
|<<mapping-id-field,`_id`>>
26+
|<<keyword, keyword>>
27+
|Unique document ID.
2728

28-
[source,esql]
29-
----
30-
FROM index METADATA _index, _id
31-
----
29+
|<<mapping-ignored-field,`_ignored`>>
30+
|<<keyword, keyword>>
31+
|Names every field in a document that was ignored when the document was indexed.
32+
33+
|<<mapping-index-field,`_index`>>
34+
|<<keyword, keyword>>
35+
|Index name.
36+
37+
|`_index_mode`
38+
|<<keyword, keyword>>
39+
|<<index-mode-setting,Index mode>>. For example: `standard`, `lookup`, or `logsdb`.
40+
41+
|`_score`
42+
|<<number,`float`>>
43+
|Query relevance score (when enabled). Scores are updated when using <<esql-search-functions,full text search functions>>.
3244

33-
Metadata fields are only available if the source of the data is an index.
34-
Consequently, `FROM` is the only source commands that supports the `METADATA`
35-
directive.
45+
|<<mapping-source-field,`_source`>>
46+
|Special `_source` type
47+
|Original JSON document body passed at index time (or a reconstructed version if <<synthetic-source,synthetic `_source`>> is enabled).
3648

37-
Once enabled, these fields will be available to subsequent processing commands, just
38-
like other index fields:
49+
|`_version`
50+
|<<number,`long`>>
51+
|Document version number
52+
|===
53+
54+
[[esql-metadata-fields-usage]]
55+
==== Usage and limitations
56+
57+
- Metadata fields are only available when the data source is an index
58+
- The `_source` type is not supported by functions
59+
- Only the `FROM` command supports the `METADATA` directive
60+
- Once enabled, metadata fields work like regular index fields
61+
62+
[[esql-metadata-fields-examples]]
63+
==== Examples
64+
65+
[[esql-metadata-fields-examples-basic]]
66+
===== Basic metadata usage
67+
68+
Once enabled, metadata fields are available to subsequent processing commands, just like other index fields:
3969

4070
[source.merge.styled,esql]
4171
----
@@ -46,6 +76,9 @@ include::{esql-specs}/metadata.csv-spec[tag=multipleIndices]
4676
include::{esql-specs}/metadata.csv-spec[tag=multipleIndices-result]
4777
|===
4878

79+
[[esql-metadata-fields-examples-aggregations]]
80+
===== Metadata fields and aggregations
81+
4982
Similar to index fields, once an aggregation is performed, a
5083
metadata field will no longer be accessible to subsequent commands, unless
5184
used as a grouping field:
@@ -58,3 +91,19 @@ include::{esql-specs}/metadata.csv-spec[tag=metaIndexInAggs]
5891
|===
5992
include::{esql-specs}/metadata.csv-spec[tag=metaIndexInAggs-result]
6093
|===
94+
95+
[[esql-metadata-fields-examples-score]]
96+
===== Sort results by search score
97+
98+
[source,esql]
99+
----
100+
FROM products METADATA _score
101+
| WHERE MATCH(description, "wireless headphones")
102+
| SORT _score DESC
103+
| KEEP name, description, _score
104+
----
105+
106+
[TIP]
107+
====
108+
Refer to <<esql-for-search>> for more information on relevance scoring and how to use `_score` in your queries.
109+
====

0 commit comments

Comments
 (0)