Hello,
I'm trying to get a sorted list of nested fields. https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-sort.html talks about how to sort the parent docs by nested field. E.g., the following
{
"query": {
"nested": {
"path": "myNestedPath",
"query": {
"exists": {
"field": "myNestedPath.myNestedField"
}
}
}
},
"_source": [
"myNestedPath.myNestedField"
],
"sort": {
"myNestedPath.myNestedField": {
"mode": "avg",
"order": "asc",
"nested": {
"path": "myNestedPath",
"filter": {
"exists": {
"field": "myNestedPath.myNestedField"
}
}
}
}
}
}
will
- Filter by documents that have
myNestedField
- Sort documents by the average of
myNestedField
- Return a list of documents containing
myNestedField
So something like
"hits": {
"hits": [
{
"_id": "containerId2",
"_score": null,
"_source": {
"myNestedPath": [
{
"myNestedField": 1
},
},
{
"_id": "containerId1",
"_score": null,
"_source": {
"myNestedPath": [
{
"myNestedField": 0
},
{
"myNestedField": 10
},
But is there a way to flatten the list and sort by myNestedField
(not avg
)? Something like
"hits": {
"hits": [
{
"myNestedField": 0
},
{
"myNestedField": 1
},
{
"myNestedField": 10
},
Thank you.