Link Search Menu Expand Document Documentation Menu

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:

PUT testindex1/_mappings
{
    "properties": {
      "patient": { 
        "properties" :
          {
            "name" : {
              "type" : "text"
            },
            "id" : {
              "type" : "keyword"
            }
          }   
      }
    }
}

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

Search for a patient with ID 123456:

GET testindex1/_search
{
  "query": {
    "term" : {
      "patient.id" : "123456"
    }
  }
}

Parameters

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

Parameter Description
dynamic Specifies whether new fields can be dynamically added to the object. Valid values are true, false, strict, and strict_allow_templates. Default is true.
enabled A 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.
properties Fields 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:

PUT testindex1/_mappings
{
    "properties": {
      "patient": { 
        "properties" :
          {
            "name" : {
              "type" : "text"
            }
          }   
      }
    }
}

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

PUT testindex1/_doc/1
{ 
  "patient": { 
    "name" : "John Doe",
    "id" : "123456"
  } 
}

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

{
  "testindex1" : {
    "mappings" : {
      "properties" : {        
        "patient" : {
          "properties" : {
            "id" : {
              "type" : "text",
              "fields" : {
                "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.
strict_allow_templates If 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.

350 characters left

Have a question? .

Want to contribute? or .