Indication of additional query results not shown due to filter


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!

(David Pilato) #2

Please format your code samples.

Also read About the Elasticsearch category

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


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.

(Nik Everett) #4

I expect you could rig something up with post_filter and an aggregation like value_count.


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.

(system) closed #6