# Combine multiple index and nested in search elasticsearch

**URL:** <https://discuss.elastic.co/t/combine-multiple-index-and-nested-in-search-elasticsearch/337753>\
**Category:** Elasticsearch\
**Created:** [July 6, 2023, 6:34am UTC](https://discuss.elastic.co/t/combine-multiple-index-and-nested-in-search-elasticsearch/337753 "2023-07-06T06:34:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![stephane\_chan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephane_chan/32/122193_2.png) [@stephane\_chan](https://discuss.elastic.co/u/stephane_chan)\
**Post date:** [July 6, 2023, 6:34am UTC](https://discuss.elastic.co/t/combine-multiple-index-and-nested-in-search-elasticsearch/337753/1 "2023-07-06T06:34:35Z")

</div>

How to search multiple indexes with nested and non-nested fields ?  
I have an audio index with the results like this :

```auto
{
        "_index" : "audios",
        "_type" : "_doc",
        "_id" : "145",
        "_score" : 9.143846,
        "_source" : {
	"id":145,
          "audio_title" : "Title",
          "main_artists" : [
            {
              "id" : 1,
              "artist_name" : "Artist_name"
            }
          ]
	}
}

```

and an index artists with results like this :

```auto
{
	  "_index" : "artists",
	  "_type" : "_doc",
	  "_id" : "34",
	  "_version" : 2,
	  "_seq_no" : 130,
	  "_primary_term" : 1,
	  "found" : true,
	  "_source" : {
		"id":34,
	   	 "artist_name" : "Artist_name"
	  }
}

```

My problem is when I do a search on the 2 indexes it gives me an error.

```auto
GET audios,artists/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "bool": {
            "should": [
              {"match_phrase_prefix": {
                "audio_title": "XXXX"
              }},
              {"nested": {
                "path": "main_artists",
                "query": {
                  "match_phrase_prefix": {
                    "main_artists.artist_name": "XXXX"
                  }
                }
              }}
            ]
          }
        }
      ]
    }
  }
}

```

The error:

```auto
"failures" : [
      {
        "shard" : 0,
        "index" : "artists",
        "node" : "sHio0-yeRaO8Z5qJXaczPw",
        "reason" : {
          "type" : "query_shard_exception",
          "reason" : "failed to create query: [nested] failed to find nested object under path [main_artists]",
          "index_uuid" : "etDWonKCSQietG3uK3ZnBA",
          "index" : "artists",
          "caused_by" : {
            "type" : "illegal_state_exception",
            "reason" : "[nested] failed to find nested object under path [main_artists]"
          }
        }
      }
    ]

```

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [July 6, 2023, 11:43am UTC](https://discuss.elastic.co/t/combine-multiple-index-and-nested-in-search-elasticsearch/337753/2 "2023-07-06T11:43:03Z")

</div>

Hi @stephane_chan

You can create separate queries for each index and run in an [msearch](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-multi-search.html).

---

<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:** [August 3, 2023, 11:43am UTC](https://discuss.elastic.co/t/combine-multiple-index-and-nested-in-search-elasticsearch/337753/3 "2023-08-03T11:43:25Z")

</div>

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