Adding metadata to a mapping

Sometimes, when working with a mapping, you need to store some additional data to be used for display purposes, ORM facilities, and permissions, or you simply need to track them in the mapping.

ElasticSearch allows you to store any kind of JSON data you want in the mapping with the _meta special field.

Getting ready

You need a working ElasticSearch cluster.

How to do it...

The _meta mapping field can be populated with any data you want:

{
  "order": {
    "_meta": {
      "attr1": ["value1", "value2"],
      "attr2": {
        "attr3": "value3"
      }
    }
  }
}

How it works...

When ElasticSearch processes a mapping and finds a _meta field, it stores the field in the global mapping status and propagates the information to all the cluster nodes.

The _meta field ...

Get ElasticSearch Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.