public static long getIndexCount(Client client, MongoDBRiverDefinition definition) { if (client.admin().indices().prepareExists(definition.getIndexName()).get().isExists()) { if (definition.isImportAllCollections()) { return client.prepareCount(definition.getIndexName()).execute().actionGet().getCount(); } else { if (client.admin().indices().prepareTypesExists(definition.getIndexName()).setTypes(definition.getTypeName()).get() .isExists()) { return client.prepareCount(definition.getIndexName()).setTypes(definition.getTypeName()).get().getCount(); } } } return 0; }
@Override public CountRequestBuilder newRequestBuilder(ElasticsearchClient client) { return new CountRequestBuilder(client, this); } }
/** * The routing values to control the shards that the search will be executed on. */ public CountRequestBuilder setRouting(String... routing) { request.routing(routing); return this; }
/** * The types of documents the query will run against. Defaults to all types. */ public CountRequestBuilder setTypes(String... types) { request.types(types); return this; }
public CountRequestBuilder<JsonInput, JsonOutput> minScore(float minScore) { request.minScore(minScore); return this; }
public CountRequestBuilder setTerminateAfter(int terminateAfter) { request().terminateAfter(terminateAfter); return this; }
/** * Sets the preference to execute the search. Defaults to randomize across shards. Can be set to * <tt>_local</tt> to prefer local shards, <tt>_primary</tt> to execute only on primary shards, * _shards:x,y to operate on shards x & y, or a custom value, which guarantees that the same order * will be used across different requests. */ public CountRequestBuilder setPreference(String preference) { request.preference(preference); return this; }
public CountRequestBuilder<JsonInput, JsonOutput> indices(String... indices) { request.indices(indices); return this; }
@Override public void execute(ActionListener<CountResponse> listener) { CountRequest countRequest = beforeExecute(request); client.execute(SearchAction.INSTANCE, countRequest.toSearchRequest(), new DelegatingActionListener<SearchResponse, CountResponse>(listener) { @Override protected CountResponse getDelegatedFromInstigator(SearchResponse response) { return new CountResponse(response); } }); }
/** * The query source to execute. */ public CountRequestBuilder setSource(byte[] querySource) { request.source(querySource); return this; }
@Override protected CountResponse getDelegatedFromInstigator(SearchResponse response) { return new CountResponse(response); } });
/** * A comma separated list of routing values to control the shards the search will be executed on. */ public CountRequestBuilder setRouting(String routing) { request.routing(routing); return this; }
public CountRequestBuilder<JsonInput, JsonOutput> types(String... types) { request.types(types); return this; }
/** * The minimum score of the documents to include in the count. Defaults to <tt>-1</tt> which means all * documents will be included in the count. */ public CountRequestBuilder setMinScore(float minScore) { request.minScore(minScore); return this; }
@Override protected CountRequest beforeExecute(CountRequest request) { if (sourceBuilder != null) { request.source(sourceBuilder); } return request; }
@Override protected CountResponse getDelegatedFromInstigator(SearchResponse response) { return new CountResponse(response); } });
public CountRequestBuilder<JsonInput, JsonOutput> routing(String... routing) { request.routing(routing); return this; }
/** * The source to execute. */ public CountRequest source(byte[] querySource) { return source(querySource, 0, querySource.length); }
@Override protected CountResponse convert(SearchResponse listenerResponse) { return new CountResponse(listenerResponse); } };