2

I've the following query which works fine on Elasticsearch 1.x but does not work on 2.x (I get doc_count: 0) since the bool filter has been deprecated. It's not quite clear to me how to re-write this query using the new Bool Query.

{
  "aggregations": {
    "events_per_period": {
      "filter": {
        "bool": {
          "must": [
            {
              "terms": {
                "message.facility": [
                  "facility1",
                  "facility2",
                  "facility3"
                ]
              }
            }
          ]
        }
      }
    }
  },
  "size": 0
}

Any help is greatly appreciated.

jeffreyveon
  • 13,400
  • 18
  • 79
  • 129

1 Answers1

1

I think you might want aggregation on multi fields with filter :- Here I assume filter for id and aggregation on facility1 and facility2 .

{
    "_source":false,
    "query": {
        "match": {
            "id": "value"
        }
    },
    "aggregations": {
        "byFacility1": {
            "terms": {
                "field": "facility1"
            },
            "aggs": {
                "byFacility2": {
                    "terms": {
                        "field": "facility2"
                    }
                }
            }
        }
    }
}

if you want aggregation on three field , check link. For java implementation link2

Community
  • 1
  • 1
Vijay
  • 4,694
  • 1
  • 30
  • 38