Custom Sort

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

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

I have update the question with sample query.

If you already have the ids, there is no need to do a search. You can get the document directly. Try using Multi Get, not only it will do what you want but it will also be faster.

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