Http HEAD request to ES in java

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

--

You can use a count :
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

Does it help?

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

Le 28 nov. 2012 à 21:03, chris harrington 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

--

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

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

--

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

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

--

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

--