# Retrieving information from elasticsearch, by the order of the input array

**URL:** <https://discuss.elastic.co/t/retrieving-information-from-elasticsearch-by-the-order-of-the-input-array/15265>\
**Category:** Elasticsearch\
**Created:** [January 16, 2014, 11:00am UTC](https://discuss.elastic.co/t/retrieving-information-from-elasticsearch-by-the-order-of-the-input-array/15265 "2014-01-16T11:00:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alves](https://avatars.discourse-cdn.com/v4/letter/a/9de0a6/32.png) [@Alves](https://discuss.elastic.co/u/Alves)\
**Post date:** [January 16, 2014, 11:00am UTC](https://discuss.elastic.co/t/retrieving-information-from-elasticsearch-by-the-order-of-the-input-array/15265/1 "2014-01-16T11:00:30Z")

</div>

Hi everyone!

Can't seem to find an answer to my doubt, so I decided to post the question  
and see if someone can help me.

In my application, I have an array of ids which comes from the backend and  
which is ordered already as I want, for example: [0] =\> 23, [1] =\> 12, [2]  
=\> 45, [3] =\> 21

I then "ask" elasticsearch the information corresponding to each id present  
in this array, using a terms filter. The problem is the results don't come  
in the order of the ids I sent, so the results get mixed up, like: [0] =\>  
21, [1] =\> 45, [2] =\> 23, [3] =\> 12

Note that I can't sort in elasticsearch by the sorting that orders the  
array in the backend.

I also can't order them in php as I'm retrieving paginated results from  
elasticsearch, so if each page had 2 results, elasticsearch could give me  
the info only for [0] =\> 21, [1] =\> 45, so I can't even order them with php.

How can I get the results ordered by the input array? Any ideas?

Thanks in advance

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/033ddde5-dc22-43ff-aca2-45d451f28339%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/033ddde5-dc22-43ff-aca2-45d451f28339%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 1:56am UTC](https://discuss.elastic.co/t/retrieving-information-from-elasticsearch-by-the-order-of-the-input-array/15265/2 "2017-07-06T01:56:26Z")

</div>


