I would like to search by an array field, and give weight depending on where the value appears in the arrays.
For example, I have 3 documents like this:
{ "foo": [1, 2, 3] }
{ "foo": [2, 3, 4] }
{ "foo": [3, 4, 5] }
and I send a query like:
{ "query": { "term": { "foo": 3 } } }
Then, I want the response to be sorted like this:
{ "foo": [3, 4, 5] }
{ "foo": [2, 3, 4] }
{ "foo": [1, 2, 3] }
I mean, the earlier 3
appears in the arrays, the higher the _score
gets.
Is there any efficient ways to do this?