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

The following examples show how to use org.elasticsearch.action.admin.indices.exists.types.TypesExistsResponse. 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: DKSearchOutputImpl.java    From dk-fitting with Apache License 2.0 6 votes vote down vote up
/**
 *
 * 获取ES某个索引下数据的总和
 * @param hostIps
 * @param clusterName
 * @param indexName
 * @param typeName
 * @param port
 * @return
 */
@Override
public long getESSum(String hostIps, String clusterName, String indexName, String typeName, int port) throws Exception {
    client=ESUtils.getClient( hostIps,port,clusterName );
    IndicesExistsResponse existsResponse = client.admin().indices().prepareExists( indexName ).execute().actionGet();
    if (!existsResponse.isExists()){
        System.out.println( "index Non-existent " );
        return -1;
    }
    TypesExistsResponse typesExistsResponse = client.admin().indices().prepareTypesExists( indexName ).setTypes( typeName ).execute().actionGet();
    if (!typesExistsResponse.isExists()){
        System.out.println( "type Non-existent " );
        return -1;
    }
    return client.prepareSearch( indexName ).setTypes( typeName ).get().getHits().totalHits;
}
 
Example #2
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 #3
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 #4
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 #5
Source File: DKSearchOutputImpl.java    From dk-fitting with Apache License 2.0 4 votes vote down vote up
/**
 * 从es导出数据,导出为xls
 * @param hostIps
 * @param clusterName
 * @param indexName
 * @param typeName
 * @param port
 * @param start
 * @param size
 * @return
 * @throws TException
 */
@Override
public String ES2XLS(String hostIps, String clusterName, String indexName, String typeName, int port, int start, int size) throws Exception {
    String type=".xlsx";
    client=ESUtils.getClient( hostIps,port,clusterName );
    IndicesExistsResponse existsResponse = client.admin().indices().prepareExists( indexName ).execute().actionGet();
    if (!existsResponse.isExists()){
        return "index Non-existent ";
    }
    TypesExistsResponse typesExistsResponse = client.admin().indices().prepareTypesExists( indexName ).setTypes( typeName ).execute().actionGet();
    if (!typesExistsResponse.isExists()){
        return "type Non-existent";
    }
    //把导出的数据以json格式写到文件里,
    BufferedOutputStream out=new BufferedOutputStream( new FileOutputStream( indexName+"_"+typeName+"_"+System.currentTimeMillis()+type,true) );
    SearchResponse response=null;

    long totalHits = client.prepareSearch( indexName ).setTypes( typeName ).get().getHits().totalHits;
    //setSearchType(SearchType.Scan) 告诉ES不需要排序只要结果返回即可 setScroll(new TimeValue(600000)) 设置滚动的时间
    //每次返回数据10000条。一直循环查询直到所有的数据都查询出来
    //setTerminateAfter(10000)    //如果达到这个数量,提前终止
    SearchRequestBuilder requestBuilder = client.prepareSearch( indexName ).setTypes( typeName ).setQuery( QueryBuilders.matchAllQuery() ).setScroll( new TimeValue(600000) );
    response=requestBuilder.setFrom( start ).setSize( size ).execute().actionGet();
    String title="ES导出";
    title=URLEncoder.encode( title,"UTF-8" );
    SearchHits searchHits = response.getHits();
    if (searchHits==null){return "no searchHit";}
    String[] keys=null;
    ArrayList<Object[]> list=new ArrayList<>(  );
    for (int i = 0; i <searchHits.getHits().length ; i++) {
        Set<String> keySet = searchHits.getHits()[i].getSource().keySet();
        keys = keySet.toArray( new String[keySet.size()] );
        Collection<Object> values = searchHits.getHits()[i].getSource().values();
        Object[] object = values.toArray( new Object[values.size()] );
        list.add( object );
    }
     ExportExcelUtils.exportExcelXSSF( title, keys, list, out );

    out.close();
    return "SUCCESS";
}
 
Example #6
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 #7
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 #8
Source File: ElasticSearchService.java    From samantha with MIT License 4 votes vote down vote up
public TypesExistsResponse existsType(String index, String type) {
    return client.admin().indices().prepareTypesExists(index)
            .setTypes(type).execute().actionGet();
}
 
Example #9
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 #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 request
 * @return The result future
 */
ActionFuture<TypesExistsResponse> typesExists(TypesExistsRequest request);
 
Example #11
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);