Mapping inheritance in elasticsearch

There is another very good feature in the mappings in es. Properties from the default type are automatically inherited by special types you define. Let’s assume the following json used to create an index.

That creates an index with the following metadata.

As you see the properties and dynamic templates are also present in the specialized types now.

GD Star Rating

Avoid dynamic mapping in elastic search

Normally elastic search is schemaless. So it doesn’t care if a document in an index has a different structure is inserted. If you want to avoid that and allow only insertion of documents that fit the schema you have defined when creating the index just add mapper -> dynamic -> false in your put request when creating the index.

But that does prevent you from inserting unknown types but you are still able to add known types without given properties or with complete other properties.

GD Star Rating

Export and import elasticsearch indices

If you want to export and import elastic search indices e.g. for backup purposes or the use case that you create the index on another machine there is the elasticsearch Knapsack plugin.

After installing (copying to plugins directory and restarting es) you are able to export or import an index by HTTP POST requests:

Will create an tar.gz ({theIndex}_import.tar.gz) within your es directory with the mapping and all data.

This could be imported by

Which will result in an bulk import to that index.

It also possible to export / import only certain types:

If you want to import to an index or type with a different name just rename the tar.gz (e.g. (thenewindex_import.tar.gz)) and it will be imported to the new index.


GD Star Rating