# Index aliases vs \_search

**URL:** <https://discuss.elastic.co/t/index-aliases-vs--search/8718>\
**Category:** Elasticsearch\
**Created:** [August 11, 2012, 12:42pm UTC](https://discuss.elastic.co/t/index-aliases-vs--search/8718 "2012-08-11T12:42:28Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marcin\_Dojwa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marcin_dojwa/32/2307_2.png) [@Marcin\_Dojwa](https://discuss.elastic.co/u/Marcin_Dojwa)\
**Post date:** [August 11, 2012, 12:42pm UTC](https://discuss.elastic.co/t/index-aliases-vs--search/8718/1 "2012-08-11T12:42:28Z")

</div>

Hi,

I will try to explain the situation first, if that is not enough I will try  
to prepare full curl example.  
I created an index alias named 1 pointing to index named 'users' with  
routing (routing=1) and filter (filtering by term: user=1). Then I indexed  
new data using created alias (1). Data is inserted in correct shard, so the  
routing value was used properly. I can get the document by \_id using  
created alias (1) but I can not \_search via this alias.

- curl -XPOST localhost:9200/users/\_search - finds indexed documents
- curl -XPOST localhost:9200/1/\_search - does not.

What is the most important, I removed alias '1' and added it again.  
Now curl -XPOST localhost:9200/1/\_search works fine and finds all the  
created documents.

Is this description enough to investigate the problem or should I try to  
recreate it step by step using curl queries ?

Thanks for help.  
Best regards.  
Marcin Dojwa.

--

---

<div class="post-metadata">

**Author:** ![Marcin\_Dojwa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marcin_dojwa/32/2307_2.png) [@Marcin\_Dojwa](https://discuss.elastic.co/u/Marcin_Dojwa)\
**Post date:** [August 11, 2012, 1:08pm UTC](https://discuss.elastic.co/t/index-aliases-vs--search/8718/2 "2012-08-11T13:08:39Z")

</div>

OK, I recreated full curl example. In this example I used 1 node only. It  
is available here: [Index aliases vs search · GitHub](https://gist.github.com/cddfb815bde791c00857)

Could you help me with this ? Unfortunately this behavior makes index  
aliases useless for me and this is necessary to make "User" data flow  
working fine 🙂

Thank you for help.  
Best regards.  
Marcin Dojwa.

2012/8/11 Marcin Dojwa [m.dojwa@livechatinc.com](mailto:m.dojwa@livechatinc.com)

> Hi,
> 
> I will try to explain the situation first, if that is not enough I will  
> try to prepare full curl example.  
> I created an index alias named 1 pointing to index named 'users' with  
> routing (routing=1) and filter (filtering by term: user=1). Then I indexed  
> new data using created alias (1). Data is inserted in correct shard, so the  
> routing value was used properly. I can get the document by \_id using  
> created alias (1) but I can not \_search via this alias.
> 
> - curl -XPOST localhost:9200/users/\_search - finds indexed documents
> - curl -XPOST localhost:9200/1/\_search - does not.
> 
> What is the most important, I removed alias '1' and added it again.  
> Now curl -XPOST localhost:9200/1/\_search works fine and finds all the  
> created documents.
> 
> Is this description enough to investigate the problem or should I try to  
> recreate it step by step using curl queries ?
> 
> Thanks for help.  
> Best regards.  
> Marcin Dojwa.

--

---

<div class="post-metadata">

**Author:** ![Marcin\_Dojwa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marcin_dojwa/32/2307_2.png) [@Marcin\_Dojwa](https://discuss.elastic.co/u/Marcin_Dojwa)\
**Post date:** [August 11, 2012, 1:09pm UTC](https://discuss.elastic.co/t/index-aliases-vs--search/8718/3 "2012-08-11T13:09:17Z")

</div>

I forgot to mention that I use ES 0.19.8.

2012/8/11 Marcin Dojwa [m.dojwa@livechatinc.com](mailto:m.dojwa@livechatinc.com)

> OK, I recreated full curl example. In this example I used 1 node only. It  
> is available here: [Index aliases vs search · GitHub](https://gist.github.com/cddfb815bde791c00857)
> 
> Could you help me with this ? Unfortunately this behavior makes index  
> aliases useless for me and this is necessary to make "User" data flow  
> working fine 🙂
> 
> Thank you for help.  
> Best regards.  
> Marcin Dojwa.
> 
> 2012/8/11 Marcin Dojwa [m.dojwa@livechatinc.com](mailto:m.dojwa@livechatinc.com)
> 
> > Hi,
> > 
> > I will try to explain the situation first, if that is not enough I will  
> > try to prepare full curl example.  
> > I created an index alias named 1 pointing to index named 'users' with  
> > routing (routing=1) and filter (filtering by term: user=1). Then I indexed  
> > new data using created alias (1). Data is inserted in correct shard, so the  
> > routing value was used properly. I can get the document by \_id using  
> > created alias (1) but I can not \_search via this alias.
> > 
> > - curl -XPOST localhost:9200/users/\_search - finds indexed documents
> > - curl -XPOST localhost:9200/1/\_search - does not.
> > 
> > What is the most important, I removed alias '1' and added it again.  
> > Now curl -XPOST localhost:9200/1/\_search works fine and finds all the  
> > created documents.
> > 
> > Is this description enough to investigate the problem or should I try to  
> > recreate it step by step using curl queries ?
> > 
> > Thanks for help.  
> > Best regards.  
> > Marcin Dojwa.

--

---

<div class="post-metadata">

**Author:** ![Marcin\_Dojwa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marcin_dojwa/32/2307_2.png) [@Marcin\_Dojwa](https://discuss.elastic.co/u/Marcin_Dojwa)\
**Post date:** [August 13, 2012, 4:53am UTC](https://discuss.elastic.co/t/index-aliases-vs--search/8718/4 "2012-08-13T04:53:00Z")

</div>

Hi,

I've just noticed that if I add any document to index 'test' before  
creating the alias it works fine. This case does not work for aliases  
created when index is empty only. Eg. if I put

curl -XPOST '[http://localhost:9200/test/documents/doc1](http://localhost:9200/test/documents/doc1)' -d  
'{"user":3,"data":"sample data"}'

right after creating index 'test', the rest curl queries works fine  
(creating alias '1' for "user":1, adding documents using alias '1' with  
"user":1 and searching documents using alias '1').

Please let me know if this always behaves properly if any document exists  
in the index first. I need to know if I can make such an assumption in my  
project.

Thank you for help.

Best regards.

2012/8/11 Marcin Dojwa [m.dojwa@livechatinc.com](mailto:m.dojwa@livechatinc.com)

> I forgot to mention that I use ES 0.19.8.
> 
> 2012/8/11 Marcin Dojwa [m.dojwa@livechatinc.com](mailto:m.dojwa@livechatinc.com)
> 
> > OK, I recreated full curl example. In this example I used 1 node only. It  
> > is available here: [Index aliases vs search · GitHub](https://gist.github.com/cddfb815bde791c00857)
> > 
> > Could you help me with this ? Unfortunately this behavior makes index  
> > aliases useless for me and this is necessary to make "User" data flow  
> > working fine 🙂
> > 
> > Thank you for help.  
> > Best regards.  
> > Marcin Dojwa.
> > 
> > 2012/8/11 Marcin Dojwa [m.dojwa@livechatinc.com](mailto:m.dojwa@livechatinc.com)
> > 
> > > Hi,
> > > 
> > > I will try to explain the situation first, if that is not enough I will  
> > > try to prepare full curl example.  
> > > I created an index alias named 1 pointing to index named 'users' with  
> > > routing (routing=1) and filter (filtering by term: user=1). Then I indexed  
> > > new data using created alias (1). Data is inserted in correct shard, so the  
> > > routing value was used properly. I can get the document by \_id using  
> > > created alias (1) but I can not \_search via this alias.
> > > 
> > > - curl -XPOST localhost:9200/users/\_search - finds indexed documents
> > > - curl -XPOST localhost:9200/1/\_search - does not.
> > > 
> > > What is the most important, I removed alias '1' and added it again.  
> > > Now curl -XPOST localhost:9200/1/\_search works fine and finds all the  
> > > created documents.
> > > 
> > > Is this description enough to investigate the problem or should I try to  
> > > recreate it step by step using curl queries ?
> > > 
> > > Thanks for help.  
> > > Best regards.  
> > > Marcin Dojwa.

--

---

<div class="post-metadata">

**Author:** ![Marcin\_Dojwa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marcin_dojwa/32/2307_2.png) [@Marcin\_Dojwa](https://discuss.elastic.co/u/Marcin_Dojwa)\
**Post date:** [August 14, 2012, 9:58pm UTC](https://discuss.elastic.co/t/index-aliases-vs--search/8718/5 "2012-08-14T21:58:08Z")

</div>

Shay, could you take a look at this ? Thank you.

Best regards.  
Marcin Dojwa.

2012/8/13 Marcin Dojwa [m.dojwa@livechatinc.com](mailto:m.dojwa@livechatinc.com)

> Hi,
> 
> I've just noticed that if I add any document to index 'test' before  
> creating the alias it works fine. This case does not work for aliases  
> created when index is empty only. Eg. if I put
> 
> curl -XPOST '[http://localhost:9200/test/documents/doc1](http://localhost:9200/test/documents/doc1)' -d  
> '{"user":3,"data":"sample data"}'
> 
> right after creating index 'test', the rest curl queries works fine  
> (creating alias '1' for "user":1, adding documents using alias '1' with  
> "user":1 and searching documents using alias '1').
> 
> Please let me know if this always behaves properly if any document exists  
> in the index first. I need to know if I can make such an assumption in my  
> project.
> 
> Thank you for help.
> 
> Best regards.
> 
> 2012/8/11 Marcin Dojwa [m.dojwa@livechatinc.com](mailto:m.dojwa@livechatinc.com)
> 
> > I forgot to mention that I use ES 0.19.8.
> > 
> > 2012/8/11 Marcin Dojwa [m.dojwa@livechatinc.com](mailto:m.dojwa@livechatinc.com)
> > 
> > > OK, I recreated full curl example. In this example I used 1 node only.  
> > > It is available here: [Index aliases vs search · GitHub](https://gist.github.com/cddfb815bde791c00857)
> > > 
> > > Could you help me with this ? Unfortunately this behavior makes index  
> > > aliases useless for me and this is necessary to make "User" data flow  
> > > working fine 🙂
> > > 
> > > Thank you for help.  
> > > Best regards.  
> > > Marcin Dojwa.
> > > 
> > > 2012/8/11 Marcin Dojwa [m.dojwa@livechatinc.com](mailto:m.dojwa@livechatinc.com)
> > > 
> > > > Hi,
> > > > 
> > > > I will try to explain the situation first, if that is not enough I will  
> > > > try to prepare full curl example.  
> > > > I created an index alias named 1 pointing to index named 'users' with  
> > > > routing (routing=1) and filter (filtering by term: user=1). Then I indexed  
> > > > new data using created alias (1). Data is inserted in correct shard, so the  
> > > > routing value was used properly. I can get the document by \_id using  
> > > > created alias (1) but I can not \_search via this alias.
> > > > 
> > > > - curl -XPOST localhost:9200/users/\_search - finds indexed documents
> > > > - curl -XPOST localhost:9200/1/\_search - does not.
> > > > 
> > > > What is the most important, I removed alias '1' and added it again.  
> > > > Now curl -XPOST localhost:9200/1/\_search works fine and finds all the  
> > > > created documents.
> > > > 
> > > > Is this description enough to investigate the problem or should I try  
> > > > to recreate it step by step using curl queries ?
> > > > 
> > > > Thanks for help.  
> > > > Best regards.  
> > > > Marcin Dojwa.

--

---

<div class="post-metadata">

**Author:** ![yarin](https://avatars.discourse-cdn.com/v4/letter/y/6a8cbe/32.png) [@yarin](https://discuss.elastic.co/u/yarin)\
**Post date:** [December 16, 2013, 12:59pm UTC](https://discuss.elastic.co/t/index-aliases-vs--search/8718/6 "2013-12-16T12:59:29Z")

</div>

I've encountered this issue myself and this thread while trying to figure this thing out.

I've found that in order to make the alias work on an empty index you need to set the mapping for the routing field (in your case, "user").

Hope this helps to anyone,  
Yarin.

---

<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, 2:01am UTC](https://discuss.elastic.co/t/index-aliases-vs--search/8718/7 "2017-07-06T02:01:01Z")

</div>


