Edit: see step-by-step and deeper explanation in post below. I am trying to sort my search results based on a field inside a nested object. Running ES 7.9. The mapping of the nested object looks like this:
{
"metaDates": {
"type": "nested",
"properties": {
"name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"qualifiers": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"value": {
"type": "date",
"format": "date_optional_time"
}
}
}
}
So there can be many metaDates objects inside one document. Those nested objects will typically look like this:
{
"metaDates": [
{
"name": "create-time",
"value": "2020-06-03T13:14:11.556Z",
"qualifiers": [
"*"
]
},
{
"name": "update-time",
"value": "2020-06-03T13:14:11.556Z",
"qualifiers": [
"*"
]
}
]
}
What I want to achieve is to order the results based on either create-time or update-time. Ascending and/or descending.
I can't make this to fully work. As it currently stands I can't enforce it to only look at the given date, it seems to me as it validates all metaDates values instead of just the one I'm interested in when ordering. (setting sort mode affects the results, that's why I think that is the case)
Sample full document:
{
"_index": "index-someitem-1630649750000",
"_type": "_doc",
"_id": "17",
"_score": null,
"_source": {
"id": 17,
"title": "test",
"metaTexts": [
{
"name": "title",
"value": "test",
"qualifiers": [
"en_US"
]
}
],
"metaDates": [
{
"name": "create-time",
"value": "2020-06-03T13:14:24.502Z",
"qualifiers": [
"*"
]
},
{
"name": "update-time",
"value": "2020-06-03T13:14:29.140Z",
"qualifiers": [
"*"
]
}
]
},
"sort": [
1591190064502
]
}
I want the whole document to be sorted based on the either create-time or update-time.
Any help is much appreciated! Thank you