Object field type

Introduced 1.0

An object field type contains a JSON object (a set of name/value pairs). A value in a JSON object may be another JSON object. It is not necessary to specify object as the type when mapping object fields because object is the default type.

Example

Create a mapping with an object field:

  1. PUT testindex1/_mappings
  2. {
  3. "properties": {
  4. "patient": {
  5. "properties" :
  6. {
  7. "name" : {
  8. "type" : "text"
  9. },
  10. "id" : {
  11. "type" : "keyword"
  12. }
  13. }
  14. }
  15. }
  16. }

copy

Index a document with an object field:

  1. PUT testindex1/_doc/1
  2. {
  3. "patient": {
  4. "name" : "John Doe",
  5. "id" : "123456"
  6. }
  7. }

copy

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).

Search for a patient with ID 123456:

  1. GET testindex1/_search
  2. {
  3. "query": {
  4. "term" : {
  5. "patient.id" : "123456"
  6. }
  7. }
  8. }

copy

Parameters

The following table lists the parameters accepted by object field types. All parameters are optional.

ParameterDescription
dynamicSpecifies whether new fields can be dynamically added to the object. Valid values are true, false, strict, and strict_allow_templates. Default is true.
enabledA Boolean value that specifies whether the JSON contents of the object should be parsed. If enabled is set to false, the object’s contents are not indexed or searchable, but they are still retrievable from the _source field. Default is true.
propertiesFields of this object, which can be of any supported type. New properties can be dynamically added to this object if dynamic is set to true.

The dynamic parameter

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:

  1. PUT testindex1/_mappings
  2. {
  3. "properties": {
  4. "patient": {
  5. "properties" :
  6. {
  7. "name" : {
  8. "type" : "text"
  9. }
  10. }
  11. }
  12. }
  13. }

copy

Then you index a document with a new id field in patient:

  1. PUT testindex1/_doc/1
  2. {
  3. "patient": {
  4. "name" : "John Doe",
  5. "id" : "123456"
  6. }
  7. }

copy

As a result, the field id is added to the mappings:

  1. {
  2. "testindex1" : {
  3. "mappings" : {
  4. "properties" : {
  5. "patient" : {
  6. "properties" : {
  7. "id" : {
  8. "type" : "text",
  9. "fields" : {
  10. "keyword" : {
  11. "type" : "keyword",
  12. "ignore_above" : 256
  13. }
  14. }
  15. },
  16. "name" : {
  17. "type" : "text"
  18. }
  19. }
  20. }
  21. }
  22. }
  23. }
  24. }

The dynamic parameter has the following valid values.

ValueDescription
trueNew fields can be added to the mapping dynamically. This is the default.
falseNew 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.
strictWhen 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.
strict_allow_templatesIf the newly detected fields match any of the predefined dynamic templates in the mapping, then they are added to the mapping; if they do not match any of them, then an exception is thrown.

Inner objects inherit the dynamic parameter value from their parent unless they declare their own dynamic parameter value.