Search result scoring

Hi,

i have question about search result order in elasticsearch.
We have different sort rules and a method for score calculation that works fine so far.

Lets assume we are performing a search and getting 10,000 results back. I want to change the query, so that the result (document) with the id=1003041 will always be shown on the result page on position 2. No matter, what score it gets.

What would be the "elastic-way" of doing this?

One way might be to change the sort to use more than the score. In other words to sort in the following order

  • First - Some script that assigns a 1 to the doc you want in the 2nd position - returns 1 if the id you want for that slot, 0 otherwise

  • Second - Score

Then when rendering the results put the item returned first from ES into the 2nd position on the UI

https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-sort.html

-Doug

1 Like

Hi Doug,

maybe i have expressed unfavourable. What i meant was, that i want the possiblity to pin any result to anywhere i want. Position 2 was just an example. Lets say, i want to show result 50 at position 2 and result 91 at position 8. But the rest should be sorted like how elastic returns the list. This is just an example. What i really want is just a possibility to show some results at a specific position i can choose.
Is there something already implemented in elastic or do i need to do it manually in my php code?

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