Object field type
Create a mapping with an object field:
Index a document with an object field:
PUT testindex1/_doc/1
{
"patient": {
"name" : "John Doe",
"id" : "123456"
}
}
Nested objects are stored as flat key/value pairs internally. To refer to a field in a nested object, use parent field
.child field
(for example, patient.id
).
Parameters
The following table lists the parameters accepted by object field types. All parameters are optional.
The dynamic
parameter specifies whether new fields can be dynamically added to an object that is already indexed.
For example, you can initially create a mapping with a patient
object that has only one field:
PUT testindex1/_mappings
{
"properties": {
"patient": {
"properties" :
"name" : {
"type" : "text"
}
}
}
}
}
As a result, the field id
is added to the mappings:
{
"testindex1" : {
"mappings" : {
"properties" : {
"patient" : {
"id" : {
"type" : "text",
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"name" : {
"type" : "text"
}
}
}
}
}
}
}
The dynamic
parameter has the following valid values.
Value | Description |
---|---|
true | New fields can be added to the mapping dynamically. This is the default. |
false | New fields cannot be added to the mapping dynamically. If a new field is detected, it is not indexed or searchable. However, it is still retrievable from the _source field. |
strict | When new fields are added to the mapping dynamically, an exception is thrown. To add a new field to an object, you have to add it to the mapping first. |
Inner objects inherit the dynamic
parameter value from their parent unless they declare their own parameter value.