Add nested and sibling aggregation in data.search() in plugin

Hi,

I am developing a custom plugin in Kibana using React, in Kibana 8.8.1.

I am using search (low-level) of data plugin to query Elasticsearch.

This is the request body:

const request = {
      id: searchId,
      trackTotalHits: true,
      params: {
        index: indexPattern,
        body: {
          size: 0,
          aggs: data.search.aggs.createAggConfigs(dataView, aggregations).toDsl() 
        },
      },
    };

where aggregations is aggs in JSON format.

Eg: when I give 2 cardinality aggreagtions,

const aggregations = [
    {   
          id: 'students_count',
          type: 'cardinality',
          params: { field: 'student.id' },
    },
    {
          id: 'teachers_count',
          type: 'cardinality',
          params: { field: 'teacher.id' },
    },
]

For the above, ES treats it as sibling aggregation and I get the output as

aggs: {
    "students_count": { ... },
    "teachers_count": { ... }
}


But when I give a terms and cardinality aggregation together, it gets treated as nested aggregation.

const aggregations = [
    {   
          id: 'students_count',
          type: 'cardinality',
          params: { field: 'student.id' },
    },
    {
          id: 'students_gender',
          type: 'terms',
          params: { field: 'student.gender' },
    },
]

For the above, ES treats it as sibling aggregation and I get the output as

aggs: {
    "students_gender": {
         "terms": {...},
         "aggs": {
             "students_count": { ... }
         }
    },
}

Why does that happen? I haven't done any other change .

How can I add in nested and siling aggregation together?

Thanks

Hi,

Would be great if someone could give some solution for this.

Things get really tough and frustrating when developing plugin in Kibana, becoz there is very very limited resources, most of which are outdated or with incorrect url references.

Hi,

Would appreciate any inputs

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