# Custom Sort

**URL:** <https://discuss.elastic.co/t/custom-sort/89851>\
**Category:** Elasticsearch\
**Created:** [June 18, 2017, 1:56pm UTC](https://discuss.elastic.co/t/custom-sort/89851 "2017-06-18T13:56:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vikash\_Gupta](https://avatars.discourse-cdn.com/v4/letter/v/6de8d8/32.png) [@Vikash\_Gupta](https://discuss.elastic.co/u/Vikash_Gupta)\
**Post date:** [June 18, 2017, 1:56pm UTC](https://discuss.elastic.co/t/custom-sort/89851/1 "2017-06-18T13:56:59Z")

</div>

I have a customer index, where i'm doing a match on multiple customer ids (to check if the customers are present), if the customers are present then I am applying filters with some conditions like minimum balance etc etc.

This works absolutely fine, but my requirement is I want to retrieve the customer information in the same order I provide the input.

Eg: If I pass customers ids as **cust-id-2, cust-id-1** , then the returned output should be in the same order. But what I get is the information of **cust-id-1** and then **cust-id-2** because **cust-id-1** was saved before **cust-id-2**.

Sample query what I'm using:

> curl -XPOST 'localhost:9200/customer/\_search?pretty' -d '  
> {"query": {  
> "bool": {  
> "should": [{"match": {"\_id": "13757e3c-275e-4254-a759-601dbe04cb18"}},  
> {"match": {"\_id": "74d23ed0-8946-4326-8d08-280c1d6c7f0b"}}]  
> }},  
> "\_source": ["id","customer-name","content-type"]  
> }'

In the above query I get data for both the ids (the ids here are uuid) but in an order where customer-id **74d23** is shown before **13757**. I want the order to be retained in the same order as input.

And solution or approach will be highly appreciated.

Thanks in advance

---

<div class="post-metadata">

**Author:** ![thiago](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thiago/32/32096_2.png) [@thiago](https://discuss.elastic.co/u/thiago)\
**Post date:** [June 18, 2017, 6:45pm UTC](https://discuss.elastic.co/t/custom-sort/89851/2 "2017-06-18T18:45:56Z")

</div>

Please, post a sample of the query you are using, with multiple customer ids.

---

<div class="post-metadata">

**Author:** ![Vikash\_Gupta](https://avatars.discourse-cdn.com/v4/letter/v/6de8d8/32.png) [@Vikash\_Gupta](https://discuss.elastic.co/u/Vikash_Gupta)\
**Post date:** [June 22, 2017, 11:51am UTC](https://discuss.elastic.co/t/custom-sort/89851/3 "2017-06-22T11:51:09Z")

</div>

Hi,  
I have update the question with sample query.

---

<div class="post-metadata">

**Author:** ![thiago](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thiago/32/32096_2.png) [@thiago](https://discuss.elastic.co/u/thiago)\
**Post date:** [June 23, 2017, 12:17am UTC](https://discuss.elastic.co/t/custom-sort/89851/4 "2017-06-23T00:17:55Z")

</div>

If you already have the ids, there is no need to do a search. You can get the document directly. Try using [Multi Get](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-multi-get.html), not only it will do what you want but it will also be faster.

---

<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 21, 2017, 12:17am UTC](https://discuss.elastic.co/t/custom-sort/89851/5 "2017-07-21T00:17:58Z")

</div>

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