use of org.elasticsearch.client.core.CountRequest in project graylog2-server by Graylog2.
the class IndexToolsAdapterES7 method count.
@Override
public long count(Set<String> indices, Optional<Set<String>> includedStreams) {
final CountRequest request = new CountRequest(indices.toArray(new String[0]), buildStreamIdFilter(includedStreams)).indicesOptions(IndicesOptions.fromOptions(true, false, true, false));
final CountResponse result = client.execute((c, requestOptions) -> c.count(request, requestOptions), "Unable to count documents of index.");
return result.getCount();
}
use of org.elasticsearch.client.core.CountRequest in project jackrabbit-oak by apache.
the class ElasticAbstractQueryTest method countDocuments.
protected long countDocuments(Tree index) {
ElasticIndexDefinition esIdxDef = getElasticIndexDefinition(index);
CountRequest request = new CountRequest(esIdxDef.getIndexAlias());
try {
return esConnection.getClient().count(request, RequestOptions.DEFAULT).getCount();
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
use of org.elasticsearch.client.core.CountRequest in project herd by FINRAOS.
the class IndexFunctionsDaoImpl method getNumberOfTypesInIndex.
@Override
public long getNumberOfTypesInIndex(final String indexName) {
LOGGER.info("Counting the number of documents in index={}.", indexName);
// Build the count request.
CountRequest countRequest = new CountRequest(indexName);
countRequest.query(QueryBuilders.matchAllQuery());
// Create the count response object.
CountResponse countResponse;
// Get the Elasticsearch REST high level client. The REST high level client is auto closeable, so use try with resources.
try (final RestHighLevelClient restHighLevelClient = elasticsearchRestHighLevelClientFactory.getRestHighLevelClient()) {
// Make the count request.
countResponse = restHighLevelClient.count(countRequest, RequestOptions.DEFAULT);
} catch (final IOException ioException) {
LOGGER.error("Caught IOException while attempting to use the ElasticsearchRestHighLevelClient.", ioException);
throw new ElasticsearchRestClientException("Caught IOException while attempting to use the ElasticsearchRestHighLevelClient.", ioException);
}
return countResponse.getCount();
}
use of org.elasticsearch.client.core.CountRequest in project molgenis by molgenis.
the class ClientFacade method getCount.
private long getCount(QueryBuilder query, List<Index> indexes) {
if (LOG.isTraceEnabled()) {
if (query != null) {
LOG.trace("Counting docs in index(es) '{}' with query '{}' ...", toString(indexes), query);
} else {
LOG.trace("Counting docs in index(es) '{}' ...", toString(indexes));
}
}
CountRequest countRequest = new CountRequest(toIndexNames(indexes));
if (query != null) {
countRequest.query(query);
}
CountResponse countResponse;
Stopwatch stopwatch = Stopwatch.createStarted();
try {
countResponse = client.count(countRequest, DEFAULT);
} catch (ElasticsearchStatusException e) {
if (e.status().getStatus() == 404) {
throw new UnknownIndexException(indexes.stream().map(Index::getName).toList(), e);
} else {
throw new IndexCountException(indexes.stream().map(Index::getName).toList(), e);
}
} catch (ElasticsearchException | IOException e) {
throw new IndexCountException(indexes.stream().map(Index::getName).toList(), e);
}
stopwatch.stop();
if (countResponse.getFailedShards() > 0) {
if (LOG.isErrorEnabled()) {
LOG.error(stream(countResponse.getShardFailures()).map(ShardSearchFailure::toString).collect(joining("\n")));
}
throw new IndexCountException(indexes.stream().map(Index::getName).toList());
}
if (TRUE.equals(countResponse.isTerminatedEarly())) {
throw new IndexCountTimeoutException(indexes.stream().map(Index::getName).toList(), stopwatch.elapsed(MILLISECONDS));
}
long totalHits = countResponse.getCount();
if (LOG.isDebugEnabled()) {
if (query != null) {
LOG.debug("Counted {} docs in index(es) '{}' with query '{}' in {}ms.", totalHits, toString(indexes), Strings.toString(query), stopwatch.elapsed(MILLISECONDS));
} else {
LOG.debug("Counted {} docs in index(es) '{}' in {}ms.", totalHits, toString(indexes), stopwatch.elapsed(MILLISECONDS));
}
}
return totalHits;
}
use of org.elasticsearch.client.core.CountRequest in project elasticflow by springwings.
the class EsWriter method getDocumentNums.
private long getDocumentNums(String instance, String storeId) throws Exception {
String iName = Common.getStoreName(instance, storeId);
CountRequest countRequest = new CountRequest(iName);
CountResponse response = getESC().getClient().count(countRequest, RequestOptions.DEFAULT);
return response.getCount();
}
Aggregations