# Adding number of hits in HTTP response headers

**URL:** https://discuss.elastic.co/t/adding-number-of-hits-in-http-response-headers/10256
**Category:** Elasticsearch
**Created:** [January 7, 2013, 11:03pm UTC](https://discuss.elastic.co/t/adding-number-of-hits-in-http-response-headers/10256 "2013-01-07T23:03:50Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Benjamin\_Deveze](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/benjamin_deveze/32/1577_2.png) [@Benjamin\_Deveze](https://discuss.elastic.co/u/Benjamin_Deveze)
#### Post date: [January 7, 2013, 11:03pm UTC](https://discuss.elastic.co/t/adding-number-of-hits-in-http-response-headers/10256/1 "2013-01-07T23:03:50Z")

</div>

I think it could be useful to return the total number of hits in HTTP  
response headers for relevant APIs like search or multisearch.

In my use case, I cache some ES results using varnish. I want to apply  
different cache policies (TTL, ...) based on the number of total hits  
matching a request. For example, you can choose not to cache requests with  
no result, or maybe cache that for 1 minute... Returning this info as a  
response header would allow doing this very easily and without parsing the  
response body.

Anyone else interested?

--

---

<div class="post-metadata">

### Author: ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)
#### Post date: [January 11, 2013, 8:04am UTC](https://discuss.elastic.co/t/adding-number-of-hits-in-http-response-headers/10256/2 "2013-01-11T08:04:20Z")

</div>

Opening up the headers in general would seem to be beneficial, but I am  
assuming there is some technical reason not to do so. If not, adding the  
number of hits seems like a great place to start.

Here is one project that has an HTTP header issue:

> **[GitHub - Asquera/elasticsearch-http-basic: HTTP Basic Authentication for...](https://github.com/Asquera/elasticsearch-http-basic)**
>
> HTTP Basic Authentication for Elasticsearch (Discontinued) - GitHub - Asquera/elasticsearch-http-basic: HTTP Basic Authentication for Elasticsearch (Discontinued)

--  
Ivan

On Mon, Jan 7, 2013 at 3:03 PM, Benjamin Devèze  
[benjamin.deveze@gmail.com](mailto:benjamin.deveze@gmail.com)wrote:

> I think it could be useful to return the total number of hits in HTTP  
> response headers for relevant APIs like search or multisearch.

--

---

<div class="post-metadata">

### Author: ![Benjamin\_Deveze](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/benjamin_deveze/32/1577_2.png) [@Benjamin\_Deveze](https://discuss.elastic.co/u/Benjamin_Deveze)
#### Post date: [January 11, 2013, 11:12pm UTC](https://discuss.elastic.co/t/adding-number-of-hits-in-http-response-headers/10256/3 "2013-01-11T23:12:48Z")

</div>

Issue opened here [Open up HTTP headers · Issue #2540 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/2540)

On Friday, January 11, 2013 9:04:20 AM UTC+1, Ivan Brusic wrote:

> Opening up the headers in general would seem to be beneficial, but I am  
> assuming there is some technical reason not to do so. If not, adding the  
> number of hits seems like a great place to start.
> 
> Here is one project that has an HTTP header issue:  
> [GitHub - Asquera/elasticsearch-http-basic: HTTP Basic Authentication for Elasticsearch (Discontinued)](https://github.com/Asquera/elasticsearch-http-basic)
> 
> --  
> Ivan
> 
> On Mon, Jan 7, 2013 at 3:03 PM, Benjamin Devèze \<[benjami...@gmail.com](mailto:benjami...@gmail.com)\<javascript:\>
> 
> > wrote:
> 
> > I think it could be useful to return the total number of hits in HTTP  
> > response headers for relevant APIs like search or multisearch.

--

---

<div class="post-metadata">

### Author: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [January 12, 2013, 8:23pm UTC](https://discuss.elastic.co/t/adding-number-of-hits-in-http-response-headers/10256/4 "2013-01-12T20:23:28Z")

</div>

Hey there,

I dont think there is a technical reason. The problem lies in the problem  
of anyone having a different use-case (as you need very different logic  
depening on your header requirements).  
The RestResponse class could easily get methods adding new headers, which  
could be parsed by the NettyHttpChannel/HttpChannel class.  
I have however not a really good idea, how to make it configurable and  
maintainable 🙂  
If you have any ideas in that regard, it might make sense to add them to  
the ticket.

--Alexander

On Sat, Jan 12, 2013 at 12:12 AM, Benjamin Devèze \<[benjamin.deveze@gmail.com](mailto:benjamin.deveze@gmail.com)

> wrote:

> Issue opened here  
> [Open up HTTP headers · Issue #2540 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/2540)
> 
> On Friday, January 11, 2013 9:04:20 AM UTC+1, Ivan Brusic wrote:
> 
> > Opening up the headers in general would seem to be beneficial, but I am  
> > assuming there is some technical reason not to do so. If not, adding the  
> > number of hits seems like a great place to start.
> > 
> > Here is one project that has an HTTP header issue: [https://github.com/](https://github.com/)\*\*  
> > Asquera/elasticsearch-http-\*\*basic[https://github.com/Asquera/elasticsearch-http-basic](https://github.com/Asquera/elasticsearch-http-basic)
> > 
> > --  
> > Ivan
> > 
> > On Mon, Jan 7, 2013 at 3:03 PM, Benjamin Devèze [benjami...@gmail.com](mailto:benjami...@gmail.com)wrote:
> > 
> > > I think it could be useful to return the total number of hits in HTTP  
> > > response headers for relevant APIs like search or multisearch.
> > 
> > --

--

---

<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 6, 2017, 2:56am UTC](https://discuss.elastic.co/t/adding-number-of-hits-in-http-response-headers/10256/5 "2017-07-06T02:56:46Z")

</div>


