David Carek
David Carek

Reputation: 1113

Is there a way to pull back the field name after aggregation?

I'm using elastic search 1.5.2 and was wondering if there is a way to add the field name to the return of an aggregation other than the name of the aggregation itself, so that age can stay age and not Customer.Age

{
    "aggregations": {
        "age": {
            "terms": {
                "field": "Customer.Age",
                "size": 10
            }
        }
    }
}

I want the return to look something like this

aggregations: {
    age: {
        doc_count_error_upper_bound: 0
        sum_other_doc_count: 0
        field: Customer.Age
        buckets: [6]
           0:  {
              key: "unknown"
              doc_count: 607103
           }            
    }

And what I currently get does not include field.

Upvotes: 0

Views: 33

Answers (1)

imotov
imotov

Reputation: 30163

This is not possible at the moment (before 2.0 is released). However, since the name of the aggregation can be essentially anything, you can encode both aggregation name and the field in the aggregation name and then parse it on the client side:

{
    "aggregations": {
        "age/Customer.Age": {
            "terms": {
                "field": "Customer.Age",
                "size": 10
            }
        }
    }
}

In v2.0 it will be possible to specify arbitrary metadata that will be returned back to the user:

{
    "aggregations": {
        "age: {
            "terms": {
                "field": "Customer.Age",
                "size": 10
            },
            "meta": {
                "field": "Customer.Age"
            }
        }
    }
}

Upvotes: 1

Related Questions