# Indication of additional query results not shown due to filter

**URL:** https://discuss.elastic.co/t/indication-of-additional-query-results-not-shown-due-to-filter/54849
**Category:** Elasticsearch
**Created:** [July 6, 2016, 4:47pm UTC](https://discuss.elastic.co/t/indication-of-additional-query-results-not-shown-due-to-filter/54849 "2016-07-06T16:47:38Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![unknownunknown](https://avatars.discourse-cdn.com/v4/letter/u/4da419/32.png) [@unknownunknown](https://discuss.elastic.co/u/unknownunknown)
#### Post date: [July 6, 2016, 4:47pm UTC](https://discuss.elastic.co/t/indication-of-additional-query-results-not-shown-due-to-filter/54849/1 "2016-07-06T16:47:38Z")

</div>

I am trying to find a way to indicate to users of an application that there are more results, but filters have caused those results to not be shown.

Suppose a request such as:

```
   {
      "query": {
        "filtered": {
          "filter": {
            "bool": {
              "must": {
                "term": {
                  "program": "tron"
                }
              }
            }
          },
          "query": {
            "match_all": {}
          }
        }
      }
    }

```

I get a result like:

```
{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "failed" : 0
  },
  "hits" : {
    "total" : 0,
    "max_score" : null,
    "hits" : []
  }
}

```

In my index, there are other programs like flynn and mcu.

I'd like to know that my filter excluded them. Knowing how many there are is less important than knowing they are or are not there. Is there a way to do this without making a second query?

Please feel free to link to existing answers to this question -- I wasn't able to find them.

Thanks for any help that can be offered!

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [July 6, 2016, 5:04pm UTC](https://discuss.elastic.co/t/indication-of-additional-query-results-not-shown-due-to-filter/54849/2 "2016-07-06T17:04:24Z")

</div>

Please format your code samples.

Also read [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21)

If you can provide a fully non working example, we might be able to help you.

---

<div class="post-metadata">

### Author: ![unknownunknown](https://avatars.discourse-cdn.com/v4/letter/u/4da419/32.png) [@unknownunknown](https://discuss.elastic.co/u/unknownunknown)
#### Post date: [July 6, 2016, 6:11pm UTC](https://discuss.elastic.co/t/indication-of-additional-query-results-not-shown-due-to-filter/54849/3 "2016-07-06T18:11:48Z")

</div>

My example works -- that isn't the problem. The problem I am having is that it doesn't provide all the information I need.

I would like to know if there is a query flag, or a way I can extend the query to tell me that there are actually 2 records that would have matched but my filter excluded those records. I did not find such a flag in the search or query API reference, so maybe there isn't a way to do that.

That said, doing the query twice, once with the filter and once without it, seems too heavy-handed. I'm hoping someone knows a better way.

---

<div class="post-metadata">

### Author: ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)
#### Post date: [July 6, 2016, 6:27pm UTC](https://discuss.elastic.co/t/indication-of-additional-query-results-not-shown-due-to-filter/54849/4 "2016-07-06T18:27:21Z")

</div>

> [@unknownunknown](#):
>
> query twice, once with the filter and once without it, seems too heavy-handed. I'm hoping someone knows a better way.

I expect you could rig something up with [post\_filter](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-post-filter.html) and an aggregation like [value\_count](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-valuecount-aggregation.html).

---

<div class="post-metadata">

### Author: ![unknownunknown](https://avatars.discourse-cdn.com/v4/letter/u/4da419/32.png) [@unknownunknown](https://discuss.elastic.co/u/unknownunknown)
#### Post date: [July 6, 2016, 6:34pm UTC](https://discuss.elastic.co/t/indication-of-additional-query-results-not-shown-due-to-filter/54849/5 "2016-07-06T18:34:16Z")

</div>

Thanks, nik. The example is kind of the inverse of my use case, but maybe it is a good starting point. I'm hopping I'll be able to figure something out from this.

---

<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:37pm UTC](https://discuss.elastic.co/t/indication-of-additional-query-results-not-shown-due-to-filter/54849/6 "2017-07-05T22:37:36Z")

</div>


