org.elasticsearch.action.admin.indices.exists.types.TypesExistsRequest Java Examples

The following examples show how to use org.elasticsearch.action.admin.indices.exists.types.TypesExistsRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RestTypesExistsAction.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
    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()));
    client.admin().indices().typesExists(typesExistsRequest, new RestResponseListener<TypesExistsResponse>(channel) {
        @Override
        public RestResponse buildResponse(TypesExistsResponse response) throws Exception {
            if (response.isExists()) {
                return new BytesRestResponse(OK);
            } else {
                return new BytesRestResponse(NOT_FOUND);
            }
        }
    });
}
 
Example #2
Source File: ESClient.java    From uavstack with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #3
Source File: TypesExistsRequestBuilder.java    From elasticshell with Apache License 2.0 5 votes vote down vote up
@Override
protected XContentBuilder toXContent(TypesExistsRequest request, TypesExistsResponse response, XContentBuilder builder) throws IOException {
    builder.startObject();
    builder.field(Fields.OK, response.isExists());
    builder.endObject();
    return builder;
}
 
Example #4
Source File: AbstractClient.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public ActionFuture<TypesExistsResponse> typesExists(TypesExistsRequest request) {
    return execute(TypesExistsAction.INSTANCE, request);
}
 
Example #5
Source File: AbstractClient.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public void typesExists(TypesExistsRequest request, ActionListener<TypesExistsResponse> listener) {
    execute(TypesExistsAction.INSTANCE, request, listener);
}
 
Example #6
Source File: DoTestTransportHookProxy.java    From uavstack with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public static void main(String[] args) throws IOException {
   
    ConsoleLogger cl = new ConsoleLogger("test");
    
    cl.setDebugable(true);
    
    UAVServer.instance().setLog(cl);
    
    UAVServer.instance().putServerInfo(CaptureConstants.INFO_APPSERVER_VENDOR, ServerVendor.TOMCAT);
    MOFAgent.mofContext.put("org.uavstack.mof.ext.clsloader", Thread.currentThread().getContextClassLoader());
    
    TransportHookProxy p = new TransportHookProxy("test", Collections.emptyMap());
    
    p.doProxyInstall(null, "testApp");
           
    String[] esAddrs = {"127.0.0.1:9300"}; 
    String clusterName = "";
    String index = "esindex";
    String type = "String";
    String alias = "alias";
    Boolean result;
    
    Settings settings = Settings.EMPTY;

    if (!StringHelper.isEmpty(clusterName)) {
            settings = Settings.builder().put("cluster.name", clusterName).build();
    }

    TransportClient client = new PreBuiltTransportClient(settings);

    for (String esAddr : esAddrs) {
        String[] ipport = esAddr.split(":");
        client.addTransportAddress(new InetSocketTransportAddress(
                new InetSocketAddress(ipport[0], DataConvertHelper.toInt(ipport[1], 9300))));
    }
    
    result = client.admin().indices().exists(new IndicesExistsRequest(index)).actionGet().isExists();
    if(result) {
        result = client.admin().indices().delete(new DeleteIndexRequest(index)).actionGet().isAcknowledged();
    }
    
    client.admin().indices().create(new CreateIndexRequest(index)).actionGet().isAcknowledged();
    
    client.admin().indices().typesExists(new TypesExistsRequest(new String[] { index }, type)).actionGet().isExists();
    
    client.admin().indices().prepareAliases().addAlias(index, alias).get().isAcknowledged();
    
    client.admin().indices().prepareAliases().removeAlias(index, alias).get().isAcknowledged();
    
    client.prepareSearch(index).setSearchType(SearchType.DFS_QUERY_THEN_FETCH).get(TimeValue.timeValueMillis(15000));

    Map<String, Object> m = new HashMap<String, Object>();
    m.put("user", "kimchy");
    m.put("postDate", new Date());
    m.put("message", "trying out Elasticsearch");
    
    BulkRequestBuilder bulkRequest = client.prepareBulk();
    bulkRequest.add(client.prepareIndex("twitter", "tweet", "1").setSource(m));
    BulkResponse bulkResponse = bulkRequest.get();
    if (bulkResponse.hasFailures()) {
        System.out.println("Failed");
    }
    
    client.close();   
}
 
Example #7
Source File: TypesExistsRequestBuilder.java    From elasticshell with Apache License 2.0 4 votes vote down vote up
public TypesExistsRequestBuilder(Client client, JsonToString<JsonInput> jsonToString, StringToJson<JsonOutput> stringToJson) {
    super(client, new TypesExistsRequest(new String[0]), jsonToString, stringToJson);
}
 
Example #8
Source File: TypesExistsRequestBuilder.java    From elasticshell with Apache License 2.0 4 votes vote down vote up
@Override
protected ActionFuture<TypesExistsResponse> doExecute(TypesExistsRequest request) {
    return client.admin().indices().typesExists(request);
}
 
Example #9
Source File: IndicesAdminClient.java    From Elasticsearch with Apache License 2.0 2 votes vote down vote up
/**
 * Types Exists.
 *
 * @param request The types exists request
 * @return The result future
 */
ActionFuture<TypesExistsResponse> typesExists(TypesExistsRequest request);
 
Example #10
Source File: IndicesAdminClient.java    From Elasticsearch with Apache License 2.0 2 votes vote down vote up
/**
 * Types exists
 *
 * @param request  The types exists
 * @param listener A listener to be notified with a result
 */
void typesExists(TypesExistsRequest request, ActionListener<TypesExistsResponse> listener);