# Searching on Multiple index with relationship

**URL:** <https://discuss.elastic.co/t/searching-on-multiple-index-with-relationship/162659>\
**Category:** Elasticsearch\
**Created:** [January 2, 2019, 1:25pm UTC](https://discuss.elastic.co/t/searching-on-multiple-index-with-relationship/162659 "2019-01-02T13:25:23Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![pranav24](https://avatars.discourse-cdn.com/v4/letter/p/b19c9b/32.png) [@pranav24](https://discuss.elastic.co/u/pranav24)\
**Post date:** [January 2, 2019, 1:25pm UTC](https://discuss.elastic.co/t/searching-on-multiple-index-with-relationship/162659/1 "2019-01-02T13:25:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pranav24](https://avatars.discourse-cdn.com/v4/letter/p/b19c9b/32.png) [@pranav24](https://discuss.elastic.co/u/pranav24)\
**Post date:** [January 4, 2019, 1:41pm UTC](https://discuss.elastic.co/t/searching-on-multiple-index-with-relationship/162659/2 "2019-01-04T13:41:09Z")

</div>

@elastic can you please answer my query?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 4, 2019, 2:01pm UTC](https://discuss.elastic.co/t/searching-on-multiple-index-with-relationship/162659/3 "2019-01-04T14:01:59Z")

</div>

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:

```auto
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": "----------------"
}

```

---

<div class="post-metadata">

**Author:** ![pranav24](https://avatars.discourse-cdn.com/v4/letter/p/b19c9b/32.png) [@pranav24](https://discuss.elastic.co/u/pranav24)\
**Post date:** [January 4, 2019, 3:36pm UTC](https://discuss.elastic.co/t/searching-on-multiple-index-with-relationship/162659/4 "2019-01-04T15:36:19Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 4, 2019, 3:52pm UTC](https://discuss.elastic.co/t/searching-on-multiple-index-with-relationship/162659/5 "2019-01-04T15:52:53Z")

</div>

> [@pranav24](#):
>
> I fear mapping explosion with that many fields in a single index.

Valid concern.

> [@pranav24](#):
>
> Can you please suggest methods to handle considering such scenarios ?

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:

```auto
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": "----------------"
        }]
}

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 1, 2019, 3:52pm UTC](https://discuss.elastic.co/t/searching-on-multiple-index-with-relationship/162659/6 "2019-02-01T15:52:54Z")

</div>

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