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

(Alves) #1

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
To view this discussion on the web visit
For more options, visit

(system) #2