Return the query terms when total hits = 0

I have the following document structure:

{
   "date" : 1400500,
   "idc" : 1001,
   "name": "somebody",
}

I am performing an _msearch query on a bunch of documents based on different values (the "idc" and a "date" range)
When ES could not find any documents for the given date range it returns:

"hits":{  
    "total":0,
    "max_score":null,
    "hits":[  
    ]
}

But, since there are N results, I cannot tell what "idc" and what "date" range was this result for.
I would like the response to have the "searched" date range and "idc" when there are no results for the given query, for example, if I am searching documents for IDC = 1001 and date between 1400100 and 1400200, and there are no results found, the response could have the date-range somewhere, something like this:

"hits":{  
    "total":0,
    "max_score":null,
    "query": {
           "date": {
               "gt": 1400100,
               "lte": 1400200,
           }
           "idc": 1001,
       }
}

That way I can tell what date range along with what IDC's has no results.

Hi, Did you try with Aggregation like date histogramme or date range ? Maybe you can do something with date histogramme having a subaggregation with 0 as sum...

https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html

Thank you, however the real world test case is more complicated, I posted that minified example to make the point, I think I will work with the "response order" based on the "request order" of _msearch. --> in PHP with loops.

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