Bucket Sort on non-numeric (keyword) field

I have index with products, each product has category and category_owner. I'd like to show on my GUI table with all categories sorted by category_owner, but table must be pageable.

I know there is a way to sort (and paging) aggregations using bucket_sort. Example

GET products/_search
{
  "size": 0, 
  "query": {
    "match_all": {}
  },
  "aggs": {
    "unique_categories": {
      "terms": {
        "field": "category",
        "size": 1000
      },
      "aggs": {
        "inner": {
          "avg": {
            "field": "price"
          }
        },
        "soring_agg": {
          "bucket_sort": {
            "sort": [
              {
                "inner": {"order": "asc"}
              }
            ],
            "from": 1,
            "size": 1
          }
        }
      }
    }
  }
}

But is there any way to sort on the non-number field? I can create term aggregation with size 1 or top_hists search, for example

      "aggs": {
        "inner": {
          "top_hits": {
            "size": 1,
            "sort": [
              {
                "@timestamp": {"order": "desc"}
              }
            ],
            "_source": {
              "includes": ["category_owner"]
            }
          }
        },
        "soring_agg": {
          "bucket_sort": {
            "sort": [
              {
                "inner": {"order": "asc"}
              }
            ]
          }
        }
      }

Bu I've got the error buckets_path must reference either a number value or a single value numeric metric aggregation, got: [InternalTopHits] at aggregation [inner]

terms aggregation also does not works

        "inner": {
          "terms": {
            "field": "category_owner",
            "size": 1
          }
        },

buckets_path must reference either a number value or a single value numeric metric aggregation, got: [StringTerms] at aggregation [inner]

Is there a way to create pagination on unique categories sorted by owner?

EDIT:
I can create all uniqe categories for each owner but I have to sort and paging it manually in my app :frowning:

  "aggs": {
    "owners": {
      "terms": {
        "field": "category_owner",
        "size": 100000
      },
      "aggs": {
        "categories": {
          "terms": {
            "field": "category",
            "size": 1000
          }
        }
      }
    }
  }

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