Searching on Multiple index with relationship

Hi All,
I have two indexes Example -Questions and Answer.
Questions index content example-
post - http://localhost:9200/question/_doc/que1

{
        "QUE_ID": "que1",
        "QUESTION_TITLE": "Sorting in Elasticsearch",
        "QUESTION_DESCRIPTION": "----------------",
}

Answer index content example-
post - http://localhost:9200/answer/_doc/que1_ans1

{
        "QUE_ID": "que1",
        "ANS_ID": "ans1"
        "ANSWER_DATA": "----------------",
}

post - http://localhost:9200/answer/_doc/que1_ans2

{
        "QUE_ID": "que1",
        "ANS_ID": "ans2"
        "ANSWER_DATA": "----------------",
}

Now while performing free text search I want to search on both indexes.
Is there any way to search on both index and at the same time I can map questions with their answers.

@elastic can you please answer my query?

You can use parent/child but I don't recommend using it unless you have no other choice.

Otherwise, I'd recommend indexing your documents as:

PUT /answer/_doc/que1_ans1
{
        "QUE_ID": "que1",
        "QUESTION_TITLE": "Sorting in Elasticsearch",
        "QUESTION_DESCRIPTION": "----------------",
        "ANS_ID": "ans1",
        "ANSWER_DATA": "----------------"
}
PUT /answer/_doc/que1_ans2
{
        "QUE_ID": "que1",
        "QUESTION_TITLE": "Sorting in Elasticsearch",
        "QUESTION_DESCRIPTION": "----------------",
        "ANS_ID": "ans2",
        "ANSWER_DATA": "----------------"
}

Thanks for your reply
The issue with the method you suggested is, I have around 1000 fields in my question index and over 1200 fields in my answer index. If I combine both of these indexes, then it be 2200 fields within a single index. I fear mapping explosion with that many fields in a single index. Can you please suggest methods to handle considering such scenarios ?

Valid concern.

I don't know. In the example you gave, there is only few fields.
I don't know your mapping and typical documents so I can't really comment on how to optimize the content. But, let's propose something in the dark:

PUT /answer/_doc/que1_ans2
{
        "QUE_ID": "que1",
        "QUESTION_TITLE": "Sorting in Elasticsearch",
        "QUESTION_DESCRIPTION": "----------------",
        "foo": [{
           "id": "ans2",
           "data": "----------------"
        },{
           "id": "bar",
           "data": "----------------"
        },{
           "id": "baz",
           "data": "----------------"
        }]
}

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.