# Http HEAD request to ES in java

**URL:** <https://discuss.elastic.co/t/http-head-request-to-es-in-java/9869>\
**Category:** Elasticsearch\
**Created:** [November 28, 2012, 8:03pm UTC](https://discuss.elastic.co/t/http-head-request-to-es-in-java/9869 "2012-11-28T20:03:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![chris\_harrington](https://avatars.discourse-cdn.com/v4/letter/c/77aa72/32.png) [@chris\_harrington](https://discuss.elastic.co/u/chris_harrington)\
**Post date:** [November 28, 2012, 8:03pm UTC](https://discuss.elastic.co/t/http-head-request-to-es-in-java/9869/1 "2012-11-28T20:03:18Z")

</div>

I've been searching the docs for the last few hours trying to find out how  
to do make a HEAD request to ES in java and I can't find anything about it.

Basically I'm trying to find out if a document exists in the most light  
weight way, the obvious solution was to use a http HEAD request but the  
closest I could find was  
client.admin().indices().prepareExists("contents").execute().actionGet();  
but that's only for checking whether the index exists not a document.

Is it even possible to do the equivalent of a HEAD request in java for ES  
(using 0.19.11 by the way), if it does exist then if someone could point me  
in the right direction that'd be great

--

---

<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:** [November 28, 2012, 8:55pm UTC](https://discuss.elastic.co/t/http-head-request-to-es-in-java/9869/2 "2012-11-28T20:55:48Z")

</div>

You can use a count :  
[http://www.elasticsearch.org/guide/reference/api/count.html](http://www.elasticsearch.org/guide/reference/api/count.html)

Or a GET if you need realtime and if you know the id : [http://www.elasticsearch.org/guide/reference/api/get.html](http://www.elasticsearch.org/guide/reference/api/get.html)

Does it help?

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 28 nov. 2012 à 21:03, chris harrington [tepoztecal@gmail.com](mailto:tepoztecal@gmail.com) a écrit :

I've been searching the docs for the last few hours trying to find out how to do make a HEAD request to ES in java and I can't find anything about it.

Basically I'm trying to find out if a document exists in the most light weight way, the obvious solution was to use a http HEAD request but the closest I could find was  
client.admin().indices().prepareExists("contents").execute().actionGet();  
but that's only for checking whether the index exists not a document.

## Is it even possible to do the equivalent of a HEAD request in java for ES (using 0.19.11 by the way), if it does exist then if someone could point me in the right direction that'd be great

--

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [November 28, 2012, 10:08pm UTC](https://discuss.elastic.co/t/http-head-request-to-es-in-java/9869/3 "2012-11-28T22:08:43Z")

</div>

Since the Java clients (NodeClient, TransportClient) of Elasticsearch do  
not use HTTP at all, it is no surprise that there is no HTTP HEAD client  
request for the RestHeadAction at all.

FYI in my upcoming Java HTTP client project, which can connect to the REST  
API, but maintains API compatibility to the TransportClient, I have added a  
sketch for such a HEAD method action to the GetRequest, checking for a  
document existence

[https://github.com/jprante/elasticsearch-client/blob/master/elasticsearch-client-ingest-http/src/main/java/org/elasticsearch/http/action/get/HttpHeadAction.java](https://github.com/jprante/elasticsearch-client/blob/master/elasticsearch-client-ingest-http/src/main/java/org/elasticsearch/http/action/get/HttpHeadAction.java)

where returning a 'null' if no document existed is rather a kludge.

The client project is not announced yet, the project and it's documentation  
is still work in progress...

Best regards,

Jörg

On Wednesday, November 28, 2012 9:03:18 PM UTC+1, chris harrington wrote:

> I've been searching the docs for the last few hours trying to find out how  
> to do make a HEAD request to ES in java and I can't find anything about it.
> 
> Basically I'm trying to find out if a document exists in the most light  
> weight way, the obvious solution was to use a http HEAD request but the  
> closest I could find was  
> client.admin().indices().prepareExists("contents").execute().actionGet();  
> but that's only for checking whether the index exists not a document.
> 
> Is it even possible to do the equivalent of a HEAD request in java for ES  
> (using 0.19.11 by the way), if it does exist then if someone could point me  
> in the right direction that'd be great

--

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [November 29, 2012, 11:43am UTC](https://discuss.elastic.co/t/http-head-request-to-es-in-java/9869/4 "2012-11-29T11:43:42Z")

</div>

HEAD is basically get with no fields:

[https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/rest/action/get/RestHeadAction.java#L49](https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/rest/action/get/RestHeadAction.java#L49)

On Wednesday, November 28, 2012 3:03:18 PM UTC-5, chris harrington wrote:

> I've been searching the docs for the last few hours trying to find out how  
> to do make a HEAD request to ES in java and I can't find anything about it.
> 
> Basically I'm trying to find out if a document exists in the most light  
> weight way, the obvious solution was to use a http HEAD request but the  
> closest I could find was  
> client.admin().indices().prepareExists("contents").execute().actionGet();  
> but that's only for checking whether the index exists not a document.
> 
> Is it even possible to do the equivalent of a HEAD request in java for ES  
> (using 0.19.11 by the way), if it does exist then if someone could point me  
> in the right direction that'd be great

--

---

<div class="post-metadata">

**Author:** ![chris\_harrington](https://avatars.discourse-cdn.com/v4/letter/c/77aa72/32.png) [@chris\_harrington](https://discuss.elastic.co/u/chris_harrington)\
**Post date:** [December 4, 2012, 11:39am UTC](https://discuss.elastic.co/t/http-head-request-to-es-in-java/9869/5 "2012-12-04T11:39:26Z")

</div>

Ok thanks guys, was hoping there was exists call on an item but looks like  
I'll have to use a get request.

On Wednesday, 28 November 2012 20:03:18 UTC, chris harrington wrote:

> I've been searching the docs for the last few hours trying to find out how  
> to do make a HEAD request to ES in java and I can't find anything about it.
> 
> Basically I'm trying to find out if a document exists in the most light  
> weight way, the obvious solution was to use a http HEAD request but the  
> closest I could find was  
> client.admin().indices().prepareExists("contents").execute().actionGet();  
> but that's only for checking whether the index exists not a document.
> 
> Is it even possible to do the equivalent of a HEAD request in java for ES  
> (using 0.19.11 by the way), if it does exist then if someone could point me  
> in the right direction that'd be great

--

---

<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, 3:01am UTC](https://discuss.elastic.co/t/http-head-request-to-es-in-java/9869/6 "2017-07-06T03:01:42Z")

</div>


