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

Schema design to store questions and answers


Using parent-child documents, we can easily find answers to questions and similarly, to questions that have a specific answer. Let's see how we can design such a schema in this section.

Imagine we have a forum like stackoverflow, where users can ask questions. Let's assume we are setting up such a schema in an index called "post".

First, let's create the index "post":

curl -XPOST localhost:9200/posts 

We created a posts index to which we index the posts by users. Now, let's give our Elasticsearch instance an insight of what we will do by defining the mapping:

curl -XPOST localhost:9200/posts/rating/_mapping -d '{
  "rating":{
    "_parent": {"type": "post"}
  }
}'

As explained earlier, here we are mapping the type "post" as the parent of the type "rating".

Now, let's index our parent and child documents:

// Already indexed

With this, we have set up the schema design to store questions and answers.

Now, let's look into a requirement. It's required for a...