Book Image

ElasticSearch Blueprints

Book Image

ElasticSearch Blueprints

Overview of this book

Table of Contents (15 chapters)
Elasticsearch Blueprints
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Nested types to the rescue


Using the nested datatype is one alternative for the inner objects and it solves the issue with the flattening of documents in Elasticsearch. Let's see how we can use the nested datatype. Let's consider the following example:

curl -XPOST localhost:9200/authors/author/1 -d'{
  "name": "Multi G. Enre",
  "books": [
    {
      "name": "Guns and lasers",
      "genre": "scifi",
      "publisher": "orbit"
    },
    {
      "name": "Dead in the night",
      "genre": "thriller",
      "publisher": "penguin"
    }
  ]
}'
curl -XPOST localhost:9200/authors/author/2 -d'{
  "name": "Alastair Reynolds",
  "books": [
    {
      "name": "Revelation Space",
      "genre": "scifi",
      "publisher": "penguin"
    }
  ]
}'

If you examine carefully, you would ideally notice no difference as to how the document looks like when compared to the inner objects. This is true as well. To make your Elasticsearch instance understand your intention of using the nested datatype, you must...