# Aggregation not working on query results

**URL:** <https://discuss.elastic.co/t/aggregation-not-working-on-query-results/145695>\
**Category:** Elasticsearch\
**Created:** [August 23, 2018, 10:08am UTC](https://discuss.elastic.co/t/aggregation-not-working-on-query-results/145695 "2018-08-23T10:08:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sangeeth\_Kumar](https://avatars.discourse-cdn.com/v4/letter/s/50afbb/32.png) [@Sangeeth\_Kumar](https://discuss.elastic.co/u/Sangeeth_Kumar)\
**Post date:** [August 23, 2018, 10:08am UTC](https://discuss.elastic.co/t/aggregation-not-working-on-query-results/145695/1 "2018-08-23T10:08:28Z")

</div>

I have query like

```auto
{
  "size": 1,
  "query": {
    "bool": {
      "must": [
        {
          "bool": {
            "must": [
              {
                "simple_query_string": {
                  "query": "sangeeth",
                  "default_operator": "OR"
                }
              }
            ]
          }
        },
        {
          "bool": {
            "should": [
              {
                "match": {
                  "CreatedBy._id": "Us_78eb6dd0a46a11e8a1b10242ac12000b"
                }
              },
              {
                "match": {
                  "_created_by._id": "Us_78eb6dd0a46a11e8a1b10242ac12000b"
                }
              },
              {
                "match": {
                  "CurrentAssignedTo._id": "Us_78eb6dd0a46a11e8a1b10242ac12000b"
                }
              }
            ],
            "minimum_should_match": 1
          }
        }
      ]
    }
  },
  "aggregations": {
    "count_per_flows": {
      "terms": {
        "field": "_type"
      },
      "aggregations": {
        "Name": {
          "terms": {
            "field": "Flow.Name.keyword"
          }
        },
        "Id": {
          "terms": {
            "field": "Flow._id.keyword"
          }
        }
      }
    }
  }
}

```

I have mentioned size as 0 in my query. I got exact one document as result. But aggregation returns result with match of all documents.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [September 20, 2018, 10:08am UTC](https://discuss.elastic.co/t/aggregation-not-working-on-query-results/145695/2 "2018-09-20T10:08:39Z")

</div>

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