Elastic Search percentile aggregations filtering issue

Hi Guys,
Below is my problem statement
I have one post search call to elasticsearch which is having query to calculate 99% percentile aggregations on one of the field. In return i am getting proper response with aggregations which is 99% percentile calculated field values. But I need to apply filter, using "bucket_selector" to filter out the values. For instance, if the percentile field value is > 60 then i need to include in my report generation.
Below is my sample aggregation request json:

{
  "aggs": {
    "2": {
       "terms": {
       "field": "component",
       "size": 500,
       "order": {
       "1": "desc"
      }
     },
     "aggs": {
          "1": {
               "percentiles": {
                   "field": "field1",
                    "percents": [
                        99
                     ],
              "keyed": false
               }
          },
    "filter_gt_than_60sec": {
      "bucket_selector": {
        "buckets_path": {
          "value": "1"
        },
        "script": "params.value > 60L"
      }
    }
  }
  }
 },
  "size": 0,
  "_source": {
	"excludes": []
  },
  "stored_fields": [
	"*"
  ],
  "script_fields": {},
  "query": {
	"bool": {
	  "must": [
		{
		  "match_all": {}
		},
		{
		  "range": {
			"@timestamp": {
			  "gte": 1547889125683,
			  "lte": 1547975525684,
			  "format": "epoch_millis"
			}
		  }
		}
	  ],
	  "filter": [],
	  "should": [],
	  "must_not": []
	}
  },
  "timeout": "30000ms"
 }

Error i am getting:

	{
		"error": {
			"root_cause": [],
			"type": "search_phase_execution_exception",
			"reason": "",
			"phase": "fetch",
			"grouped": true,
			"failed_shards": [],
			"caused_by": {
				"type": "aggregation_execution_exception",
				"reason": "buckets_path must reference either a number value or a single value numeric metric aggregation, got: org.elasticsearch.search.aggregations.metrics.percentiles.tdigest.InternalTDigestPercentiles"
			}
		},
		"status": 503
	}

I understood from the above error is that, I can't apply "bucket_selector" on percentile fields, Then how can i filter out the aggregated response "field1" whose values are greater than 60. I read about "percentile_bucket" but it is to calculate percentiles on field values; but it is not filter on the aggregated percentile fields. Thanks in advance.

I'm not at a computer where I can test this, but you should be able to use bracket syntax to access the individual percents of the percentiles agg. Something like:

"buckets_path": {
  "value": "1[99.0]"
},

Thanks a lot. It is working now with the format that you provided above.

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