0

I learned how to write a ES query for calculating the percentile, but it seems to work for one field. If I want percentile on multiple fields, it does not work.

 "aggs": {
        "distinct_UUID": {
            "terms": {
                "field": "cust_uuid"
            },
                "aggs": {
                  "perf_percentiles" : {
                "percentiles" : {
      "field":"A",
      "field":"B"
      }
      }

The code above works fine if I have just one field (field A or B, but not both) in the percentiles section, but I want to have 10 fields or more. How can I solve for it?

Sam G
  • 151
  • 1
  • 3
  • 13

1 Answers1

2

Simply add more sub-aggregations, one for each field:

{
  "aggs": {
    "distinct_UUID": {
      "terms": {
        "field": "cust_uuid"
      },
      "aggs": {
        "percentile_a": {
          "percentiles": {
            "field": "A"
          }
        },
        "percentile_b": {
          "percentiles": {
            "field": "B"
          }
        },
        "percentile_c": {
          "percentiles": {
            "field": "C"
          }
        }
      }
    }
  }
}
Val
  • 207,596
  • 13
  • 358
  • 360
  • Thanks! That was helpful. I use the ES Definitive Guide from the website. Are there other references that you recommend? – Sam G Apr 18 '17 at 18:17