Elastic search mapping for nested json objects Elastic search mapping for nested json objects json json

Elastic search mapping for nested json objects


You can do it like this:

PUT /my_index{  "mappings": {    "blogpost": {      "properties": {        "comments": {          "type": "nested",           "properties": {            "name":    { "type": "string"  },            "comment": { "type": "string"  },            "age":     { "type": "short"   },            "stars":   { "type": "short"   },            "date":    { "type": "date"    }          }        }      }    }  }}

Quote from this section of the ES definitive guide.


Arrays of objects do not work as you would expect: you cannot query each object independently of the other objects in the array. If you need to be able to do this then you should use the nested data type instead of the object data type.

  tasks: {      type: 'nested',      properties: {        id: {          type: 'text',        },        description: {          type: 'text',        },        assignee: {          type: 'nested',          properties: {            id: {              type: 'text',            },            thumbnail: {              type: 'text',            },          },        },      },    },

https://www.elastic.co/guide/en/elasticsearch/reference/current/nested.htmlhttps://www.elastic.co/guide/en/elasticsearch/reference/current/array.html


put /my_index/_mapping/my_type { "person": {   "properties": {     "name" : {       "type": "text",       "analyzer": "string_lowercase",       "fields": {         "keyword": {           "type": "keyword"         }       }      },      "car": {        "type" : "nested",        "properties": {          "make": {             "type": "text",            "analyzer": "string_lowercase",            "fields": {            "keyword": {              "type": "keyword"            }           }          },          "model": {             "type": "text",            "analyzer": "string_lowercase",            "fields": {            "keyword": {              "type": "keyword"             }            }           }         }       }     }    }   }