I'm trying to sort a search result in ElasticSearch 5 by a nested set of key value pairs. Ie.:
I have the following result (pseudo structure, for the sake of keeping it simple):
{
"hit1": {
"nested_objects": [
{
"Key": "abc",
"Value": 0.1
},
{
"Key": "def",
"Value": 0.3
}
]
},
"hit2": {
"nested_objects": [
{
"Key": "abc",
"Value": 0.9
},
{
"Key": "def",
"Value": 0.1
}
]
}
}
I'd like that to be sorted by "highest Value where Key = 'abc'", which would mean that "hit2" would come out on top.
My mapping is as follows:
{
"test_index": {
"mappings": {
"test_type": {
"properties": {
"nested_objects": {
"type": "nested",
"properties": {
"Key": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"Value": {
"type": "float"
}
}
}
}
}
}
}
}
I've tried to follow the following suggestions:
Sort elastic search query based on a nested key value array
Sort nested object in Elasticsearch
...but I consistently get the following error:
"Fielddata is disabled on text fields by default"
An example of a sorting attempt that reproduces this:
{
"sort": [
{
"nested_objects.Key": {
"order": "desc",
"nested_path": "nested_objects",
"nested_filter": {
"term": { "nested_objects.Key": "abc" }
}
}
}
]
}
What is the best practice way of solving this? Is enabling field data (which uses a lot of ram) really the only option here?