olivere / elastic

Deprecated: Use the official Elasticsearch client for Go at https://github.com/elastic/go-elasticsearch
https://olivere.github.io/elastic/
MIT License
7.42k stars 1.15k forks source link

Global + Filters Aggregations with DSL? #1606

Closed quesurifn closed 2 years ago

quesurifn commented 2 years ago

Which version of Elastic are you using?

[X] elastic.v7 (for Elasticsearch 7.x) [ ] elastic.v6 (for Elasticsearch 6.x) [ ] elastic.v5 (for Elasticsearch 5.x) [ ] elastic.v3 (for Elasticsearch 2.x) [ ] elastic.v2 (for Elasticsearch 1.x)

Please describe the expected behavior

I'm trying to get aggregations like this:

"aggs": {
    "Total": {
      "global": {},
      "aggs": {
        "user_term": {
          "filter": {
            "term": {
              "user.id": "kimchy"
            }
          }
        },
        "tag_term": {
          "filter": {
            "term": {
              "tags": "production"
            }
          }
        },
        "age_range_not": {
          "filter": {
            "bool": {
              "must_not": {
                "range": {
                  "age": {
                    "gte": 10,
                    "lte": 20
                  }
                }
              }
            }
          }
        },
        "age_range": {
          "filter": {
            "range": {
              "age": {
                "gte": 10,
                "lte": 20
              }
            }
          }
        }
      }
    }
  }

But have been unable to get this structure. I've tried global and subquery as filters and vice versa. How do I use the provided DSL to achieve this?

quesurifn commented 2 years ago

@olivere Hey mate, do you have any advice here?