mirror of
https://github.com/elastic/elasticsearch.git
synced 2025-04-26 08:07:27 -04:00
This PR adds support for a new mapping parameter to the configuration of the object mapper (root as well as individual fields), that makes it possible to store metrics data where it's common to have fields with dots in their names in the following format: ``` { "metrics.time" : 10, "metrics.time.min" : 1, "metrics.time.max" : 500 } ``` Instead of expanding dotted paths the their corresponding object structure, objects can be configured to preserve dots in field names, in which case they can only hold leaf sub-fields and no further objects. The mapping parameter is called subobjects and controls whether an object can hold other objects (defaults to true) or not. The following example shows how it can be configured in the mappings: ``` { "mappings" : { "properties" : { "metrics" : { "type" : "object", "subobjects" : false } } } } ``` Closes #63530
107 lines
3.2 KiB
Text
107 lines
3.2 KiB
Text
[[subobjects]]
|
|
=== `subobjects`
|
|
|
|
When indexing a document or updating mappings, Elasticsearch accepts fields that contain dots in their names,
|
|
which get expanded to their corresponding object structure. For instance, the field `metrics.time.max`
|
|
is mapped as a `max` leaf field with a parent `time` object, belonging to its parent `metrics` object.
|
|
|
|
The described default behaviour is reasonable for most scenarios, but causes problems in certain situations
|
|
where for instance a field `metrics.time` holds a value too, which is common when indexing metrics data.
|
|
A document holding a value for both `metrics.time.max` and `metrics.time` gets rejected given that `time`
|
|
would need to be a leaf field to hold a value as well as an object to hold the `max` sub-field.
|
|
|
|
The `subobjects` setting, which can be applied only to the top-level mapping definition and
|
|
to <<object,`object`>> fields, disables the ability for an object to hold further subobjects and makes it possible
|
|
to store documents where field names contain dots and share common prefixes. From the example above, if the object
|
|
container `metrics` has `subobjects` set to `false`, it can hold values for both `time` and `time.max` directly
|
|
without the need for any intermediate object, as dots in field names are preserved.
|
|
|
|
[source,console]
|
|
--------------------------------------------------
|
|
PUT my-index-000001
|
|
{
|
|
"mappings": {
|
|
"properties": {
|
|
"metrics": {
|
|
"type": "object",
|
|
"subobjects": false <1>
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
PUT my-index-000001/_doc/metric_1
|
|
{
|
|
"metrics.time" : 100, <2>
|
|
"metrics.time.min" : 10,
|
|
"metrics.time.max" : 900
|
|
}
|
|
|
|
PUT my-index-000001/_doc/metric_2
|
|
{
|
|
"metrics" : {
|
|
"time" : 100, <3>
|
|
"time.min" : 10,
|
|
"time.max" : 900
|
|
}
|
|
}
|
|
|
|
GET my-index-000001/_mapping
|
|
--------------------------------------------------
|
|
|
|
[source,console-result]
|
|
--------------------------------------------------
|
|
{
|
|
"my-index-000001" : {
|
|
"mappings" : {
|
|
"properties" : {
|
|
"metrics" : {
|
|
"subobjects" : false,
|
|
"properties" : {
|
|
"time" : {
|
|
"type" : "long"
|
|
},
|
|
"time.min" : { <4>
|
|
"type" : "long"
|
|
},
|
|
"time.max" : {
|
|
"type" : "long"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
--------------------------------------------------
|
|
|
|
<1> The `metrics` field cannot hold other objects.
|
|
<2> Sample document holding flat paths
|
|
<3> Sample document holding an object (configured to not hold subobjects) and its leaf sub-fields
|
|
<4> The resulting mapping where dots in field names were preserved
|
|
|
|
The entire mapping may be configured to not support subobjects as well, in which case the document can
|
|
only ever hold leaf sub-fields:
|
|
|
|
[source,console]
|
|
--------------------------------------------------
|
|
PUT my-index-000001
|
|
{
|
|
"mappings": {
|
|
"subobjects": false <1>
|
|
}
|
|
}
|
|
|
|
PUT my-index-000001/_doc/metric_1
|
|
{
|
|
"time" : "100ms", <2>
|
|
"time.min" : "10ms",
|
|
"time.max" : "900ms"
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
<1> The entire mapping is configured to not support objects.
|
|
<2> The document does not support objects
|
|
|
|
The `subobjects` setting for existing fields and the top-level mapping definition cannot be updated.
|