# How aggs by id and order result by title?

**URL:** <https://discuss.elastic.co/t/how-aggs-by-id-and-order-result-by-title/99486>\
**Category:** Elasticsearch\
**Created:** [September 5, 2017, 8:41pm UTC](https://discuss.elastic.co/t/how-aggs-by-id-and-order-result-by-title/99486 "2017-09-05T20:41:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gaz](https://avatars.discourse-cdn.com/v4/letter/g/c2a13f/32.png) [@Gaz](https://discuss.elastic.co/u/Gaz)\
**Post date:** [September 5, 2017, 8:41pm UTC](https://discuss.elastic.co/t/how-aggs-by-id-and-order-result-by-title/99486/1 "2017-09-05T20:41:30Z")

</div>

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](https://stackoverflow.com/questions/46054711/how-aggs-by-id-and-order-result-by-title-elasticsearch-5-5)

_sorry for my english_

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 3, 2017, 8:41pm UTC](https://discuss.elastic.co/t/how-aggs-by-id-and-order-result-by-title/99486/2 "2017-10-03T20:41:40Z")

</div>

Closed on October 3, 2017, 8:41pm UTC

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