Indexing data that is not flat
Not all data is flat like that which we have been using since Chapter 2, Searching Your Data. Of course if we are building our system, which ElasticSearch will be a part of, we can create a structure that is convenient for ElasticSearch. However, it doesn't need to be flat, it can be more object-oriented. Let's see how to create mappings that use fully structured JSON objects.
Data
Let's assume we have the following data (we store it in the file called structured_data.json
):
{ "book" : { "author" : { "name" : { "firstName" : "Fyodor", "lastName" : "Dostoevsky" } }, "isbn" : "123456789", "englishTitle" : "Crime and Punishment", "originalTitle" : "Преступлéние и наказáние", "year" : 1886, "characters" : [ { "name" : "Raskolnikov" }, { "name" : "Sofia" } ], "copies" : 0 } }
As you can see, the data is not flat. It contains arrays and nested objects, so we can't use our mappings that we used previously. But we...