# Indexing using main index while search using index aliases

**URL:** <https://discuss.elastic.co/t/indexing-using-main-index-while-search-using-index-aliases/25101>\
**Category:** Elasticsearch\
**Created:** [July 8, 2015, 12:14am UTC](https://discuss.elastic.co/t/indexing-using-main-index-while-search-using-index-aliases/25101 "2015-07-08T00:14:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![samirn](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@samirn](https://discuss.elastic.co/u/samirn)\
**Post date:** [July 8, 2015, 12:14am UTC](https://discuss.elastic.co/t/indexing-using-main-index-while-search-using-index-aliases/25101/1 "2015-07-08T00:14:32Z")

</div>

I am hoping to avoid insert to each individual index alias. Is there a way I can upload data to the main index while the data is queried via aliases created on the index. I am using the index template to define a template with aliases.

suppose -  
main index: space, and have 2 index aliases: space-stars, space-planets  
I would like to insert data using the main index  
curl -XPOST localhost:9200/space/all -d ....  
and then query using an alias (which should filter the data that matches the alias' filter pattern)  
curl -XGET localhost:9200/space-stars/\_search  
curl -XGET localhost:9200/space-planets/\_search

So far in my testing by inserting 8 records (4 records for each alias based on filter definition), I see random results. Sometimes I see the search (using the alias) return just 1 hit (most often the first inserted item) and other times nothing. If I query the "space" index directly, all 8 records are returned.

Thanks,  
Samir

---

<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:** [July 8, 2015, 12:57am UTC](https://discuss.elastic.co/t/indexing-using-main-index-while-search-using-index-aliases/25101/2 "2015-07-08T00:57:30Z")

</div>

This should work fine. It's the best practice IMO:

Index using index name  
Query using aliases

May be you did something wrong when defining your aliases?

---

<div class="post-metadata">

**Author:** ![samirn](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@samirn](https://discuss.elastic.co/u/samirn)\
**Post date:** [July 8, 2015, 6:47pm UTC](https://discuss.elastic.co/t/indexing-using-main-index-while-search-using-index-aliases/25101/3 "2015-07-08T18:47:19Z")

</div>

Thanks David. Upon your confirmation, I went with explicit removal of aliases before deleting the index, and then populate the index, and search the aliases. That seems to be working consistently now. Earlier I presumed that index deletion will fully clean up aliases but apparently not and it may have lead to inconsistent results when querying thru aliases.

---

<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 6, 2017, 12:02am UTC](https://discuss.elastic.co/t/indexing-using-main-index-while-search-using-index-aliases/25101/4 "2017-07-06T00:02:46Z")

</div>


