I'd like to sort nested Elasticsearch using multiple values. Here's an example:
I have some Events
, which have a nested topics
, like this
"_source": {
"topics": [
{
"type": "Tools",
"name": "Data Science",
"id": 19
},
{
"type": "Challenges",
"name": "Disaster Resilience",
"id": 1
},
{
"type": "Tools",
"name": "Entrepreneurship",
"id": 21
},
{
"type": "Challenges",
"name": "Prosperity",
"id": 8
}
]
...
}
Also, Members
have the same nested topics
, using the same structure.
What I'd like to do is sort the Events according to the Members topics. For instance, if a Member has three matching topics with an Event, and two with another, I'd like to show the most matching Event first.
I tried something like this:
"sort":[
{
"topics.id":{
"nested_path":"topics",
"mode":"sum",
"order":"asc",
"nested_filter":{
"match": {
"topics.id": 13
}
}
}
}
]
Which works for a specific Topic. But I'd like to do something like this below, using multiple values in the sort
, returning the most matched Event first. In this case, an Event with Topics 13 and 14 will be returned first than an Event with just Topic 13 and all the other non-matching Events will be shown after.
"sort":[
{
"topics.id":{
"nested_path":"topics",
"mode":"sum",
"order":"asc",
"nested_filter":[
{
"match": {
"topics.id": 13
}
},
{
"match": {
"topics.id": 14
}
}
]
}
}
]
EDITED: Here's the error I got when using this last snippet:
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "[field_sort] nested_filter doesn't support values of type: START_ARRAY"
}
],
"type": "illegal_argument_exception",
"reason": "[field_sort] nested_filter doesn't support values of type: START_ARRAY"
},
"status": 400
}
But this unfortunately does not work. Is there a way to do this? Am I missing some awesome feature here?
Thanks!