I have an ElasticSearch index that looks something like this:
{ "mappings": { "article": { "properties": { "title": { "type": "string" }, "tags": { "type": "keyword" }, } } }
And data that looks something like this:
{ "title": "Something about Dogs", "tags": ["articles", "dogs"] }, { "title": "Something about Cats", "tags": ["articles", "cats"] }, { "title": "Something about Dog Food", "tags": ["articles", "dogs", "dogfood"] }
If I am looking for a dog , I will receive the first and third documents, as expected. And I can weigh the search documents as I like (in fact, I use the function_score query to weigh on a bunch of fields that are not related to this question).
What I would like to do is sort the tags field so that the most relevant tags are returned first without affecting the sort order of the documents themselves. Therefore, I hope to get this result:
{ "title": "Something about Dog Food", "tags": ["dogs", "dogfood", "articles"] }
Instead of what I am getting now:
{ "title": "Something about Dog Food", "tags": ["articles", "dogs", "dogfood"] }
The sort documentation and function evaluation don't cover my case. Any help appreciated. Thanks!