2015-08-06 11:24:29 -04:00
|
|
|
[[properties]]
|
|
|
|
=== `properties`
|
|
|
|
|
|
|
|
Type mappings, <<object,`object` fields>> and <<nested,`nested` fields>>
|
|
|
|
contain sub-fields, called `properties`. These properties may be of any
|
2020-07-07 14:59:35 -04:00
|
|
|
<<mapping-types,data type>>, including `object` and `nested`. Properties can
|
2015-08-06 11:24:29 -04:00
|
|
|
be added:
|
|
|
|
|
|
|
|
* explicitly by defining them when <<indices-create-index,creating an index>>.
|
2016-02-09 05:07:32 -05:00
|
|
|
* explicitly by defining them when adding or updating a mapping type with the <<indices-put-mapping,PUT mapping>> API.
|
2015-08-06 11:24:29 -04:00
|
|
|
* <<dynamic-mapping,dynamically>> just by indexing documents containing new fields.
|
|
|
|
|
|
|
|
Below is an example of adding `properties` to a mapping type, an `object`
|
|
|
|
field, and a `nested` field:
|
|
|
|
|
2019-09-06 11:31:13 -04:00
|
|
|
[source,console]
|
2015-08-06 11:24:29 -04:00
|
|
|
--------------------------------------------------
|
2019-01-22 09:13:52 -05:00
|
|
|
PUT my_index
|
2015-08-06 11:24:29 -04:00
|
|
|
{
|
|
|
|
"mappings": {
|
2019-01-22 09:13:52 -05:00
|
|
|
"properties": { <1>
|
|
|
|
"manager": {
|
|
|
|
"properties": { <2>
|
|
|
|
"age": { "type": "integer" },
|
|
|
|
"name": { "type": "text" }
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"employees": {
|
|
|
|
"type": "nested",
|
|
|
|
"properties": { <3>
|
|
|
|
"age": { "type": "integer" },
|
|
|
|
"name": { "type": "text" }
|
2015-08-06 11:24:29 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-14 11:47:53 -05:00
|
|
|
PUT my_index/_doc/1 <4>
|
2015-08-06 11:24:29 -04:00
|
|
|
{
|
|
|
|
"region": "US",
|
|
|
|
"manager": {
|
|
|
|
"name": "Alice White",
|
|
|
|
"age": 30
|
|
|
|
},
|
|
|
|
"employees": [
|
|
|
|
{
|
|
|
|
"name": "John Smith",
|
|
|
|
"age": 34
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "Peter Brown",
|
|
|
|
"age": 26
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
2019-09-06 11:31:13 -04:00
|
|
|
|
2019-01-22 09:13:52 -05:00
|
|
|
<1> Properties in the top-level mappings definition.
|
2015-08-06 11:24:29 -04:00
|
|
|
<2> Properties under the `manager` object field.
|
|
|
|
<3> Properties under the `employees` nested field.
|
|
|
|
<4> An example document which corresponds to the above mapping.
|
|
|
|
|
2015-08-12 15:21:37 -04:00
|
|
|
TIP: The `properties` setting is allowed to have different settings for fields
|
|
|
|
of the same name in the same index. New properties can be added to existing
|
|
|
|
fields using the <<indices-put-mapping,PUT mapping API>>.
|
|
|
|
|
2015-08-06 11:24:29 -04:00
|
|
|
==== Dot notation
|
|
|
|
|
|
|
|
Inner fields can be referred to in queries, aggregations, etc., using _dot
|
|
|
|
notation_:
|
|
|
|
|
2019-09-06 11:31:13 -04:00
|
|
|
[source,console]
|
2015-08-06 11:24:29 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
GET my_index/_search
|
|
|
|
{
|
|
|
|
"query": {
|
|
|
|
"match": {
|
2018-06-06 03:53:14 -04:00
|
|
|
"manager.name": "Alice White"
|
2015-08-06 11:24:29 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
"aggs": {
|
|
|
|
"Employees": {
|
|
|
|
"nested": {
|
|
|
|
"path": "employees"
|
|
|
|
},
|
|
|
|
"aggs": {
|
|
|
|
"Employee Ages": {
|
|
|
|
"histogram": {
|
2018-06-06 03:53:14 -04:00
|
|
|
"field": "employees.age",
|
2015-08-06 11:24:29 -04:00
|
|
|
"interval": 5
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
2016-04-29 10:42:03 -04:00
|
|
|
// TEST[continued]
|
2015-08-06 11:24:29 -04:00
|
|
|
|
|
|
|
IMPORTANT: The full path to the inner field must be specified.
|