Search in sources :

Example 1 with TypesExistsRequest

use of org.elasticsearch.action.admin.indices.exists.types.TypesExistsRequest in project elasticsearch by elastic.

the class RestTypesExistsAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    TypesExistsRequest typesExistsRequest = new TypesExistsRequest(Strings.splitStringByCommaToArray(request.param("index")), Strings.splitStringByCommaToArray(request.param("type")));
    typesExistsRequest.local(request.paramAsBoolean("local", typesExistsRequest.local()));
    typesExistsRequest.indicesOptions(IndicesOptions.fromRequest(request, typesExistsRequest.indicesOptions()));
    return channel -> client.admin().indices().typesExists(typesExistsRequest, new RestResponseListener<TypesExistsResponse>(channel) {

        @Override
        public RestResponse buildResponse(TypesExistsResponse response) throws Exception {
            if (response.isExists()) {
                return new BytesRestResponse(OK, BytesRestResponse.TEXT_CONTENT_TYPE, BytesArray.EMPTY);
            } else {
                return new BytesRestResponse(NOT_FOUND, BytesRestResponse.TEXT_CONTENT_TYPE, BytesArray.EMPTY);
            }
        }
    });
}
Also used : BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) RestResponse(org.elasticsearch.rest.RestResponse) IOException(java.io.IOException) NOT_FOUND(org.elasticsearch.rest.RestStatus.NOT_FOUND) RestController(org.elasticsearch.rest.RestController) Strings(org.elasticsearch.common.Strings) BytesArray(org.elasticsearch.common.bytes.BytesArray) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) Settings(org.elasticsearch.common.settings.Settings) TypesExistsRequest(org.elasticsearch.action.admin.indices.exists.types.TypesExistsRequest) IndicesOptions(org.elasticsearch.action.support.IndicesOptions) RestRequest(org.elasticsearch.rest.RestRequest) OK(org.elasticsearch.rest.RestStatus.OK) TypesExistsResponse(org.elasticsearch.action.admin.indices.exists.types.TypesExistsResponse) NodeClient(org.elasticsearch.client.node.NodeClient) HEAD(org.elasticsearch.rest.RestRequest.Method.HEAD) RestResponseListener(org.elasticsearch.rest.action.RestResponseListener) TypesExistsRequest(org.elasticsearch.action.admin.indices.exists.types.TypesExistsRequest) RestResponse(org.elasticsearch.rest.RestResponse) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) TypesExistsResponse(org.elasticsearch.action.admin.indices.exists.types.TypesExistsResponse) IOException(java.io.IOException)

Example 2 with TypesExistsRequest

use of org.elasticsearch.action.admin.indices.exists.types.TypesExistsRequest in project uavstack by uavorg.

the class ESClient method existType.

/**
 * existType
 *
 * @param index
 * @param type
 * @return
 */
public boolean existType(String index, String type) {
    TypesExistsRequest request = new TypesExistsRequest(new String[] { index }, type);
    TypesExistsResponse resp = client.admin().indices().typesExists(request).actionGet();
    if (resp.isExists()) {
        return true;
    }
    return false;
}
Also used : TypesExistsRequest(org.elasticsearch.action.admin.indices.exists.types.TypesExistsRequest) TypesExistsResponse(org.elasticsearch.action.admin.indices.exists.types.TypesExistsResponse)

Example 3 with TypesExistsRequest

use of org.elasticsearch.action.admin.indices.exists.types.TypesExistsRequest in project alien4cloud by alien4cloud.

the class EsDaoCrudTest method assertTypeExists.

private void assertTypeExists(String indexName, String typeToCheck, boolean expected) throws InterruptedException, ExecutionException, JsonGenerationException, JsonMappingException, IntrospectionException, IOException {
    final ActionFuture<TypesExistsResponse> typeExistsFuture = nodeClient.admin().indices().typesExists(new TypesExistsRequest(new String[] { indexName }, typeToCheck));
    final TypesExistsResponse response = typeExistsFuture.get();
    assertEquals(expected, response.isExists());
}
Also used : TypesExistsRequest(org.elasticsearch.action.admin.indices.exists.types.TypesExistsRequest) TypesExistsResponse(org.elasticsearch.action.admin.indices.exists.types.TypesExistsResponse)

Aggregations

TypesExistsRequest (org.elasticsearch.action.admin.indices.exists.types.TypesExistsRequest)3 TypesExistsResponse (org.elasticsearch.action.admin.indices.exists.types.TypesExistsResponse)3 IOException (java.io.IOException)1 IndicesOptions (org.elasticsearch.action.support.IndicesOptions)1 NodeClient (org.elasticsearch.client.node.NodeClient)1 Strings (org.elasticsearch.common.Strings)1 BytesArray (org.elasticsearch.common.bytes.BytesArray)1 Settings (org.elasticsearch.common.settings.Settings)1 BaseRestHandler (org.elasticsearch.rest.BaseRestHandler)1 BytesRestResponse (org.elasticsearch.rest.BytesRestResponse)1 RestController (org.elasticsearch.rest.RestController)1 RestRequest (org.elasticsearch.rest.RestRequest)1 HEAD (org.elasticsearch.rest.RestRequest.Method.HEAD)1 RestResponse (org.elasticsearch.rest.RestResponse)1 NOT_FOUND (org.elasticsearch.rest.RestStatus.NOT_FOUND)1 OK (org.elasticsearch.rest.RestStatus.OK)1 RestResponseListener (org.elasticsearch.rest.action.RestResponseListener)1