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

Get Elasticsearch Blueprints now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.