Force document on top

Hi!

I would like to put some items first in my search results. Let me explain by giving an example.

Example:
Let's say I have a forum with pinned items. The pinned items has an order.
Now, when I search, I would like to force these pinned items to always appear on the top, in the correct order.

  • Pinned #1
  • Pinned #2
  • Search result #1
  • Search result #2
    ...

Is it possible to do something like this in ES?

If you have a pinned field, you can sort by it then by _score.

We don't know if it is pinned until runtime so we cannot index it... It depends on the user :-/

I think I'd deal with that on the client side.
Maintain a list of pinned docs there...

Or if you know their _ids, write a function_score query which gives a high score for a _ids filter.

That might work.

Thank you for your answers.

Yes, I could handle it on the client side but it would be nice to have it in the ES query. It makes pagination and so on a bit easier.

I know the items when I perform the query so I guess I can boost them a lot to push them to the top. I just have to make sure they end up in the correct order.

I just wanted to check if there was a better way to do it.