Reputation: 1378
While indexing a document, Elasticsearch will automatically create the mapping for the missing fields (inside document)
Is it possible to configure (or) is there a configuration where we can instruct the elasticsearch NOT to create missing fields, instead ignore.
Basically, we use Java POJO, we use the instance of same POJO to index the document (by converting this instance to json using GSON library) and also use some of the fields in this POJO for some external purpose.
So when we set those fields used for external purpose, but send the document to Elasticsearch, these additional fields are also saved. We want to avoid that.
Upvotes: 7
Views: 6847
Reputation: 27487
Yes, it is possible to disable the dynamic mapping feature within Elasticsearch so that mappings are not created dynamically when new fields are ingested. From the documentation:
Dynamic mapping
When Elasticsearch encounters a previously unknown field in a document, it uses dynamic mapping to determine the datatype for the field and automatically adds the new field to the type mapping.
Sometimes this is the desired behaviour and sometimes it isn’t. Perhaps you don’t know what fields will be added to your documents later on, but you want them to be indexed automatically. Perhaps you just want to ignore them. Or — especially if you are using Elasticsearch as a primary datastore — perhaps you want unknown fields to throw an exception to alert you to the problem.
Fortunately, you can control this behaviour with the dynamic setting, which accepts the following options:
true - Add new fields dynamically — the default
false - Ignore new fields
strict - Throw an exception if an unknown field is encountered
https://www.elastic.co/guide/en/elasticsearch/reference/current/dynamic-mapping.html
Upvotes: 5