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
loading...

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
loading...

Using map-reduce with MongoDB

Besides its other features MongoDB also support aggreagtions within the database. One way is to use the built-in aggreagtion framework and the other map-reduce.
From my point of view the aggregation frameworks works good for simple aggregations but for complicated stuff like summing up and also average calcluations map-reduce is the better approach.

The only thing that went wrong in the beginning is that map and reduce have to return the same data because reducing is only a step for summing up all the stuff. Average calculation has to be done in a final step, called finalize.

The output is written to a collection.

See the examples here.

As a performance indicator I can say that it aggregates 4 mio documents (summing up some internal structures and taking averages on main categories and overall) in about 5 minutes and was 4 hours with pure Java implementation before.

GD Star Rating
loading...