use of org.elasticsearch.client.core.CountRequest in project jobrunr by jobrunr.
the class ElasticSearchStorageProvider method countJobs.
long countJobs(QueryBuilder queryBuilder) throws IOException {
CountRequest countRequest = new CountRequest(jobIndexName);
countRequest.query(queryBuilder);
CountResponse countResponse = client.count(countRequest, RequestOptions.DEFAULT);
return countResponse.getCount();
}
use of org.elasticsearch.client.core.CountRequest in project jobrunr by jobrunr.
the class ElasticSearchStorageProvider method getJobStats.
@Override
public JobStats getJobStats() {
try {
GetResponse getResponse = client.get(new GetRequest(metadataIndexName, STATS_ID), RequestOptions.DEFAULT);
SearchRequest searchRequest = new SearchRequest(jobIndexName);
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.query(matchAllQuery());
searchSourceBuilder.aggregation(terms(Jobs.FIELD_STATE).field(Jobs.FIELD_STATE));
searchRequest.source(searchSourceBuilder);
SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
Terms terms = searchResponse.getAggregations().get(Jobs.FIELD_STATE);
List<? extends Terms.Bucket> buckets = terms.getBuckets();
return new JobStats(Instant.now(), 0L, buckets.stream().filter(bucket -> StateName.SCHEDULED.name().equals(bucket.getKeyAsString())).map(MultiBucketsAggregation.Bucket::getDocCount).findFirst().orElse(0L), buckets.stream().filter(bucket -> StateName.ENQUEUED.name().equals(bucket.getKeyAsString())).map(MultiBucketsAggregation.Bucket::getDocCount).findFirst().orElse(0L), buckets.stream().filter(bucket -> StateName.PROCESSING.name().equals(bucket.getKeyAsString())).map(MultiBucketsAggregation.Bucket::getDocCount).findFirst().orElse(0L), buckets.stream().filter(bucket -> StateName.FAILED.name().equals(bucket.getKeyAsString())).map(MultiBucketsAggregation.Bucket::getDocCount).findFirst().orElse(0L), buckets.stream().filter(bucket -> StateName.SUCCEEDED.name().equals(bucket.getKeyAsString())).map(MultiBucketsAggregation.Bucket::getDocCount).findFirst().orElse(0L), ((Number) getResponse.getSource().getOrDefault(FIELD_VALUE, 0L)).longValue(), buckets.stream().filter(bucket -> StateName.DELETED.name().equals(bucket.getKeyAsString())).map(MultiBucketsAggregation.Bucket::getDocCount).findFirst().orElse(0L), (int) client.count(new CountRequest(recurringJobIndexName), RequestOptions.DEFAULT).getCount(), (int) client.count(new CountRequest(backgroundJobServerIndexName), RequestOptions.DEFAULT).getCount());
} catch (IOException e) {
throw new StorageException(e);
}
}
use of org.elasticsearch.client.core.CountRequest in project spring-data-elasticsearch by spring-projects.
the class RequestConverters method count.
/**
* Creates a count request.
*
* @param countRequest the search defining the data to be counted
* @return Elasticsearch count request
* @since 4.0
*/
public static Request count(CountRequest countRequest) {
Request request = new Request(HttpMethod.POST.name(), endpoint(countRequest.indices(), countRequest.types(), "_count"));
Params params = new Params(request);
addCountRequestParams(params, countRequest);
if (countRequest.source() != null) {
request.setEntity(createEntity(countRequest.source(), REQUEST_BODY_CONTENT_TYPE));
}
return request;
}
use of org.elasticsearch.client.core.CountRequest in project graylog2-server by Graylog2.
the class MessagesES7IT method messageCount.
@Override
protected long messageCount(String indexName) {
this.elasticsearch.elasticsearchClient().execute((c, requestOptions) -> c.indices().refresh(new RefreshRequest(), requestOptions));
final CountRequest countRequest = new CountRequest(indexName);
final CountResponse result = this.elasticsearch.elasticsearchClient().execute((c, requestOptions) -> c.count(countRequest, requestOptions));
return result.getCount();
}
use of org.elasticsearch.client.core.CountRequest in project apm-agent-java by elastic.
the class AbstractEs6_4ClientInstrumentationTest method testCountRequest_validateSpanContentAndDbContext.
@Test
public void testCountRequest_validateSpanContentAndDbContext() throws Exception {
createDocument();
reporter.reset();
CountRequest countRequest = new CountRequest(INDEX);
SearchSourceBuilder countSourceBuilder = new SearchSourceBuilder();
countSourceBuilder.query(QueryBuilders.termQuery(FOO, BAR));
countRequest.source(countSourceBuilder);
CountResponse responses = doCount(countRequest);
assertThat(responses.getCount()).isEqualTo(1);
List<Span> spans = reporter.getSpans();
assertThat(spans).hasSize(1);
Span span = spans.get(0);
validateSpanContent(span, String.format("Elasticsearch: POST /%s/_count", INDEX), 200, "POST");
validateDbContextContent(span, "{\"query\":{\"term\":{\"foo\":{\"value\":\"bar\",\"boost\":1.0}}}}");
deleteDocument();
}
Aggregations