# Filter with aggregation not working

**URL:** <https://discuss.elastic.co/t/filter-with-aggregation-not-working/58101>\
**Category:** Elasticsearch\
**Created:** [August 16, 2016, 6:40am UTC](https://discuss.elastic.co/t/filter-with-aggregation-not-working/58101 "2016-08-16T06:40:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Selvam\_ayyanar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/selvam_ayyanar/32/11101_2.png) [@Selvam\_ayyanar](https://discuss.elastic.co/u/Selvam_ayyanar)\
**Post date:** [August 16, 2016, 6:40am UTC](https://discuss.elastic.co/t/filter-with-aggregation-not-working/58101/1 "2016-08-16T06:40:23Z")

</div>

Hi All,  
below query not working please help on this:

```auto
{
    "query" : {
    "bool": {
    "must": [
         {"term": {"field1": "value1"}},
         {"wildcard": {"field2": "*value2*"}}
            ],
    "must_not": [],
    "should": []
      }
    },
    "aggs" : {
        "genres": {
            "terms" : { "field" : "field3" }
        }
    }
}

```

in result, the **bucket shows empty**

but its able to get with below

```auto
{
    "query" : {
    "bool": {
    "must": [
         {"term": {"field1": "value1"}},
         {"wildcard": {"field2": "*value2*"}}
            ],
    "must_not": [],
    "should": []
      }
    },
    "aggs" : {
        "genres": {
            "terms" : { "field" : " **field2**" }
        }
    }
}

```

**and**

```auto
{
    "query" : {
    "bool": {
    "must": [
         {"term": {"field1": "value1"}},
         {"wildcard": {"field2": "*value2*"}}
            ],
    "must_not": [],
    "should": []
      }
    },
    "aggs" : {
        "genres": {
            "terms" : { "field" : " **field1**" }
        }
    }
}

```

---

<div class="post-metadata">

**Author:** ![Selvam\_ayyanar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/selvam_ayyanar/32/11101_2.png) [@Selvam\_ayyanar](https://discuss.elastic.co/u/Selvam_ayyanar)\
**Post date:** [August 18, 2016, 6:04am UTC](https://discuss.elastic.co/t/filter-with-aggregation-not-working/58101/2 "2016-08-18T06:04:56Z")

</div>

Hi all,

any one please help on this

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [August 19, 2016, 10:20am UTC](https://discuss.elastic.co/t/filter-with-aggregation-not-working/58101/3 "2016-08-19T10:20:13Z")

</div>

Does `field3` have doc values enabled? And does this field have values for the documents that match your query?

---

<div class="post-metadata">

**Author:** ![Selvam\_ayyanar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/selvam_ayyanar/32/11101_2.png) [@Selvam\_ayyanar](https://discuss.elastic.co/u/Selvam_ayyanar)\
**Post date:** [August 20, 2016, 6:51am UTC](https://discuss.elastic.co/t/filter-with-aggregation-not-working/58101/4 "2016-08-20T06:51:16Z")

</div>

Hi jpountz,  
Thanks for reply.

doc values not enabled for the **field3** ,

its work with  
{  
"aggs" : {  
"genres": {  
"terms" : { "field" : " **field1**" }  
}  
}  
}

i don't know why its not work with bool query .

---

<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:** [July 5, 2017, 10:26pm UTC](https://discuss.elastic.co/t/filter-with-aggregation-not-working/58101/5 "2017-07-05T22:26:30Z")

</div>


