org.elasticsearch.client.core.CountRequest Java Examples

The following examples show how to use org.elasticsearch.client.core.CountRequest. 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: AbstractEs6_4ClientInstrumentationTest.java    From apm-agent-java with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example #2
Source File: EsRestClientContainer.java    From frostmourne with MIT License 5 votes vote down vote up
public long totalCount(BoolQueryBuilder boolQueryBuilder, String[] indices) throws IOException {
    CountRequest countRequest = new CountRequest(indices);
    SearchSourceBuilder countSourceBuilder = new SearchSourceBuilder();
    countSourceBuilder.query(boolQueryBuilder);
    countRequest.source(countSourceBuilder);

    CountResponse countResponse = this.fetchHighLevelClient().count(countRequest, RequestOptions.DEFAULT);
    return countResponse.getCount();
}
 
Example #3
Source File: DefaultElasticSearchService.java    From jetlinks-community with Apache License 2.0 5 votes vote down vote up
private Mono<CountResponse> doCount(Mono<CountRequest> requestMono) {
    return requestMono.flatMap((request) ->
        ReactorActionListener
            .<CountResponse>mono(listener ->
                restClient
                    .getQueryClient()
                    .countAsync(request, RequestOptions.DEFAULT, listener)))
        .onErrorResume(err -> {
            log.error("query elastic error", err);
            return Mono.empty();
        });
}
 
Example #4
Source File: DefaultElasticSearchService.java    From jetlinks-community with Apache License 2.0 5 votes vote down vote up
private Mono<CountRequest> createCountRequest(QueryParam queryParam, String index) {
    QueryParam tempQueryParam = queryParam.clone();
    tempQueryParam.setPaging(false);
    tempQueryParam.setSorts(Collections.emptyList());
    return indexManager
        .getIndexMetadata(index)
        .map(metadata -> ElasticSearchConverter.convertSearchSourceBuilder(queryParam, metadata))
        .switchIfEmpty(Mono.fromSupplier(() -> ElasticSearchConverter.convertSearchSourceBuilder(queryParam, null)))
        .flatMap(builder -> this.getIndexForSearch(index)
            .map(idx -> new CountRequest(idx).source(builder)));
}
 
Example #5
Source File: AbstractEs6_4ClientInstrumentationTest.java    From apm-agent-java with Apache License 2.0 5 votes vote down vote up
protected CountResponse doCount(CountRequest countRequest) throws IOException, ExecutionException, InterruptedException {
    if (async) {
        ClientMethod<CountRequest, CountResponse> method =
            (request, options, listener) -> client.countAsync(request, options, listener);
        return invokeAsync(countRequest, method);
    }
    return client.count(countRequest, RequestOptions.DEFAULT);
}
 
Example #6
Source File: StatusMetricsBolt.java    From storm-crawler with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(Tuple input) {
    _collector.ack(input);

    // this bolt can be connected to anything
    // we just want to trigger a new search when the input is a tick tuple
    if (!TupleUtils.isTick(input)) {
        return;
    }

    for (StatusActionListener listener : listeners) {
        // still waiting for results from previous request
        if (!listener.isReady()) {
            LOG.debug("Not ready to get counts for status {}",
                    listener.name);
            continue;
        }
        CountRequest request = new CountRequest(indexName);
        if (!listener.name.equalsIgnoreCase("TOTAL")) {
            SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
            sourceBuilder.query(QueryBuilders.termQuery("status",
                    listener.name));
            request.source(sourceBuilder);
        }
        listener.busy();
        connection.getClient().countAsync(request, RequestOptions.DEFAULT,
                listener);
    }
}