Java rest client 5.6, fetch if "Type" exists


(Neha Goswami) #1

I am working on migration from Transport client to rest client:
To start with the simple change:
earlier in transport client to find a "type" exists ,we did this:

boolean typexists = this.client.admin().indices().prepareTypesExists("recovery_index").setTypes("recovery_type").get(TimeValue.timeValueSeconds(this.timeoutSecs)).isExists();

how do we achieve this using restClient? In rest Client we can get this as response:

Response response=restClient.performRequest("GET", "/recovery_index/recovery_type/_search", Collections.singletonMap("pretty", "true"));

now further from this response any quicker way to get if type exists??


(Luca Cavanna) #2

Types exists can be done through a HEAD request to the /{index}/_mapping/{type} endpoint. It will return no response body, but the returned status code will tell you whether the type exists (200) or not (404).


(system) #3

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