Search code examples
jsonelasticsearchelasticsearch-mapping

How to add a list to Elasticsearch mapping


I have the following JSON format and want to create a mapping for it from Elasticsearch console :

{
  "properties": {
    "@timestamp" : {
     "type" : "date"
    },
    "list": [
      {
        "name": "John",
        "age": "37",
        "title": "Tester"
      }
    ]
  }
}

Solution

  • There's no list or array type in ES, you simply declare objects and then you can add a list of those objects to your documents:

    PUT your-index
    {
       "mappings": {
          "properties": {
             "@timestamp" : {
                "type" : "date"
             },
             "list": {
                "type": "object",
                "properties": {
                   "name": {
                      "type": "text"
                   },
                   "age": {
                      "type": "integer"
                   },
                   "title": {
                      "type": "text"
                   }
                }
             }
          }
       }
    }