# How to perform a GetById from multiple indices

**URL:** <https://discuss.elastic.co/t/how-to-perform-a-getbyid-from-multiple-indices/29001>\
**Category:** Elasticsearch\
**Created:** [September 10, 2015, 9:20am UTC](https://discuss.elastic.co/t/how-to-perform-a-getbyid-from-multiple-indices/29001 "2015-09-10T09:20:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![VinsYu](https://avatars.discourse-cdn.com/v4/letter/v/4491bb/32.png) [@VinsYu](https://discuss.elastic.co/u/VinsYu)\
**Post date:** [September 10, 2015, 9:20am UTC](https://discuss.elastic.co/t/how-to-perform-a-getbyid-from-multiple-indices/29001/1 "2015-09-10T09:20:26Z")

</div>

Use Case:  
I have two indices (archive and active). Now during search and retrieve, it should be able to perform the action on both indices. However, for update and create new documents, it should be able to execute the action on the active index only.

Currently, I created two aliases. alias1 points to both archive and active index while alias2 only points to active index.

During search, I'm able to search on both indices using alias1. However, when calling method

```
public GetRequestBuilder prepareGet(String index, String type, String id)

```

I'm getting an error:

```
Alias [alias1] has more than one indices associated with it 
[[achive, active]], can't execute a single index op]"

```

What's the best way to handle this situation? Clients and users performing getById does not know whether the content is in archive or active index. This is transparent to them.

Thanks,  
/Vins

---

<div class="post-metadata">

**Author:** ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)\
**Post date:** [September 10, 2015, 10:44am UTC](https://discuss.elastic.co/t/how-to-perform-a-getbyid-from-multiple-indices/29001/2 "2015-09-10T10:44:45Z")

</div>

You could use the [mget API](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-multi-get.html) to perform a get on both indices and then choose which response to use in your response to your user (which ever get succeeds presumably)

---

<div class="post-metadata">

**Author:** ![VinsYu](https://avatars.discourse-cdn.com/v4/letter/v/4491bb/32.png) [@VinsYu](https://discuss.elastic.co/u/VinsYu)\
**Post date:** [September 10, 2015, 11:03am UTC](https://discuss.elastic.co/t/how-to-perform-a-getbyid-from-multiple-indices/29001/3 "2015-09-10T11:03:09Z")

</div>

Thanks Colin. I'll try this out.

Regard,  
/Vins

---

<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:** [July 5, 2017, 11:51pm UTC](https://discuss.elastic.co/t/how-to-perform-a-getbyid-from-multiple-indices/29001/4 "2017-07-05T23:51:17Z")

</div>


