Javascript aggregator using in postAggregations

I am trying to write javascript aggregator for my druid queries.i need count of “lastest_instrument_id”.

i have been trying below query


“queryType”: “topN”,

“dataSource”: “client_1_SLAMonitoring”,

“dimension”: “sla_state_value”,

“threshold”: 5,

“metric”: “count”,

“granularity”: “all”,

“filter”: {

"type": "and",

"fields": [


    "type": "selector",

    "dimension": "process_defid",

    "value": "Reporting_Test:1:94ac81a3-174f-11ea-9b52-2267ce80250d"



    "type": "selector",

    "dimension": "sla_state_value",

    "value": 4


“aggregations”: [






“postAggregations”: [


“type”: “javascript”,

“name”: “totalcount”,

“fieldNames”: [“lastest_instrument_id”],

“function”: “function(lastest_instrument_id) { return lastest_instrument_id.length;}”}],

“intervals”: [




but iam getting below exception:


“error” : “Unknown exception”,

“errorMessage” : “Instantiation of [simple type, class org.apache.druid.query.topn.TopNQuery] value failed: Must have an AggregatorFactory or PostAggregator for metric[count], gave[[StringFirstAggregatorFactory{name=‘lastest_instrument_id’, fieldName=‘instrument_id’, maxStringBytes=1024’}]] and [[]]”,

“errorClass” : “com.fasterxml.jackson.databind.JsonMappingException”,

“host” : null


if anything is missing in this quey .please let me know.

plz reply anyone

What is your schema? Can you try breaking it smaller parts? Like does just getting the metric to work correctly? Or does just the postAggregator work?