forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add per-field metadata. (elastic#49419)
This PR adds per-field metadata that can be set in the mappings and is later returned by the field capabilities API. This metadata is completely opaque to Elasticsearch but may be used by tools that index data in Elasticsearch to communicate metadata about fields with tools that then search this data. A typical example that has been requested in the past is the ability to attach a unit to a numeric field. In order to not bloat the cluster state, Elasticsearch requires that this metadata be small: - keys can't be longer than 20 chars, - values can only be numbers or strings of no more than 50 chars - no inner arrays or objects, - the metadata can't have more than 5 keys in total. Given that metadata is opaque to Elasticsearch, field capabilities don't try to do anything smart when merging metadata about multiple indices, the union of all field metadatas is returned. Here is how the meta might look like in mappings: ```json { "properties": { "latency": { "type": "long", "meta": { "unit": "ms" } } } } ``` And then in the field capabilities response: ```json { "latency": { "long": { "searchable": true, "aggreggatable": true, "meta": { "unit": [ "ms" ] } } } } ``` When there are no conflicts, values are arrays of size 1, but when there are conflicts, Elasticsearch includes all unique values in this array, without giving ways to know which index has which metadata value: ```json { "latency": { "long": { "searchable": true, "aggreggatable": true, "meta": { "unit": [ "ms", "ns" ] } } } } ``` Closes elastic#33267
- Loading branch information
1 parent
36dccaa
commit a456e59
Showing
32 changed files
with
721 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
[[mapping-field-meta]] | ||
=== `meta` | ||
|
||
Metadata attached to the field. This metadata is opaque to Elasticsearch, it is | ||
only useful for multiple applications that work on the same indices to share | ||
meta information about fields such as units | ||
|
||
[source,console] | ||
------------ | ||
PUT my_index | ||
{ | ||
"mappings": { | ||
"properties": { | ||
"latency": { | ||
"type": "long", | ||
"meta": { | ||
"unit": "ms" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
------------ | ||
// TEST | ||
|
||
NOTE: Field metadata enforces at most 5 entries, that keys have a length that | ||
is less than or equal to 20, and that values are strings whose length is less | ||
than or equal to 50. | ||
|
||
NOTE: Field metadata is updatable by submitting a mapping update. The metadata | ||
of the update will override the metadata of the existing field. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
rest-api-spec/src/main/resources/rest-api-spec/test/field_caps/20_meta.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
--- | ||
"Merge metadata across multiple indices": | ||
|
||
- skip: | ||
version: " - 7.99.99" | ||
reason: Metadata support was added in 7.6 | ||
|
||
- do: | ||
indices.create: | ||
index: test1 | ||
body: | ||
mappings: | ||
properties: | ||
latency: | ||
type: long | ||
meta: | ||
unit: ms | ||
metric_type: gauge | ||
|
||
- do: | ||
indices.create: | ||
index: test2 | ||
body: | ||
mappings: | ||
properties: | ||
latency: | ||
type: long | ||
meta: | ||
unit: ns | ||
metric_type: gauge | ||
|
||
- do: | ||
indices.create: | ||
index: test3 | ||
|
||
- do: | ||
field_caps: | ||
index: test3 | ||
fields: [latency] | ||
|
||
- is_false: fields.latency.long.meta.unit | ||
|
||
- do: | ||
field_caps: | ||
index: test1 | ||
fields: [latency] | ||
|
||
- match: {fields.latency.long.meta.unit: ["ms"]} | ||
- match: {fields.latency.long.meta.metric_type: ["gauge"]} | ||
|
||
- do: | ||
field_caps: | ||
index: test1,test3 | ||
fields: [latency] | ||
|
||
- match: {fields.latency.long.meta.unit: ["ms"]} | ||
- match: {fields.latency.long.meta.metric_type: ["gauge"]} | ||
|
||
- do: | ||
field_caps: | ||
index: test1,test2,test3 | ||
fields: [latency] | ||
|
||
- match: {fields.latency.long.meta.unit: ["ms", "ns"]} | ||
- match: {fields.latency.long.meta.metric_type: ["gauge"]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.