How aggs by id and order result by title?

Mapping:

{
  "mappings": {
    "post": {
      "properties": {
        "tags": {
          "type": "nested"
        }
      }
    }
  }
}

Posts:

{
  "title": "some title",
  "message": "some message",
  "tags": [
    {
      "id": 1,
      "title": "some tag title"
    },
    {
      "id": 2,
      "title": "some tag title 2"
    },
    {
      "id": 3,
      "title": "some tag title 3"
    }
  ]
}

{
  "title": "some title 2",
  "message": "some message 2",
  "tags": [
    {
      "id": 2,
      "title": "some tag title 2"
    }
  ]
}

{
  "title": "some title 3",
  "message": "some message 3",
  "tags": [
    {
      "id": 1,
      "title": "some tag title"
    },
    {
      "id": 2,
      "title": "some tag title 2"
    }
  ]
}

My request:

{
  "size": 0,
  "aggs": {
    "group_by_tags": {
      "nested": {
        "path": "tags"
      },
      "aggs": {
        "tags": {
          "terms": {
            "field": "tags.id",
            "order": {
              "titles": "asc"
            }
          },
          "aggs": {
            "titles": {
              "terms": {
                "field": "tags.title.keyword"
              }
            }
          }
        }
      }
    }
  }
}

But I get error:

"reason": {
  "type": "aggregation_execution_exception",
  "reason": "Invalid terms aggregation order path [titles]. Terms buckets can only be sorted on a sub-aggregator path that is built out of zero or more single-bucket aggregations within the path and a final single-bucket or a metrics aggregation at the path end."
}

What I do wrong?

P.S.
I duplicate my question from https://stackoverflow.com/questions/46054711/how-aggs-by-id-and-order-result-by-title-elasticsearch-5-5

sorry for my english

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.