AnswerBun.com

Elasticsearch Top level aggregation / search body metadata

Stack Overflow Asked by Joe - Elasticsearch Handbook on January 5, 2022

It’s possible to include sub-aggregation metadata like so:

GET kibana_sample_data_flights/_search
{
  "size": 0,
  "query": ...,
  "aggs": {
    "by_delay": {
      "terms": {
        "field": "FlightDelay"
      },
      "meta": {                <---
        "key": "val"
      }
    },
    "by_cancelled": {
      "terms": {
        "field": "Cancelled"
      },
      "meta": {                <---
        "key": "val"
      }
    }
  }
}

Now, there are dozens of such sub-aggs and some shared metadata. Although it only applies to the aggs, I wouldn’t mind putting it somewhere in the query section. So is there a per-search-body metadata field?

I’m thinking I could wrap all these sub-aggs inside of a match_all filter group:

{
  "size": 0,
  "query": ...,
  "aggs": {
    "meta_parent": {
      "filter": {
        "match_all": {}
      },
      "meta": {
        "shared": "meta"
      },
      "aggs": {
        "by_delay": ...,
        "by_cancelled": ...
      }
    }
  }
}

Is there a better way?

One Answer

If you don't have any query part, I would leverage the global aggregation, like this:

{
  "size": 0,
  "aggs": {
    "meta_parent": {
      "global": {},
      "meta": {
        "shared": "meta"
      },
      "aggs": {
        "by_delay": ...,
        "by_cancelled": ...
      }
    }
  }
}

Otherwise, what you suggested with a filter/match_all aggregation can work, too:

{
  "size": 0,
  "aggs": {
    "meta_parent": {
      "filter": {
        "match_all": {}
      },
      "meta": {
        "shared": "meta"
      },
      "aggs": {
        "by_delay": ...,
        "by_cancelled": ...
      }
    }
  }
}

Answered by Val on January 5, 2022

Add your own answers!

Related Questions

Remove item from state

3  Asked on December 5, 2020 by clayton-crockville

 

How to concatenate 3 lists even if there are a list null?

2  Asked on December 5, 2020 by alexz

       

Angular 8: Select first element of ng-content

1  Asked on December 5, 2020 by ijustdev

     

docker-compose volume empty

3  Asked on December 5, 2020 by kerby82

   

Extract value of column from a line (variable)

4  Asked on December 4, 2020 by user4516211

       

Merge Two Files in Weka based on date

1  Asked on December 4, 2020 by spwath

 

Set Session ID Cookie in Nuxt Auth

1  Asked on December 4, 2020 by dominooch

   

Warnings in gcc compiler

1  Asked on December 3, 2020 by hygor-marques

     

Ask a Question

Get help from others!

© 2023 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP