Search in sources :

Example 1 with CountResult

use of io.searchbox.core.CountResult in project graylog2-server by Graylog2.

the class MessagesES6IT method messageCount.

@Override
protected long messageCount(String indexName) {
    final Count count = new Count.Builder().addIndex(indexName).build();
    final CountResult result = JestUtils.execute(jestClient(elasticsearch), count, () -> "Unable to count documents");
    return result.getCount().longValue();
}
Also used : Count(io.searchbox.core.Count) CountResult(io.searchbox.core.CountResult)

Example 2 with CountResult

use of io.searchbox.core.CountResult in project graylog2-server by Graylog2.

the class IndexToolsAdapterES6 method count.

@Override
public long count(Set<String> indices, Optional<Set<String>> includedStreams) {
    final SearchSourceBuilder queryBuilder = new SearchSourceBuilder().query(buildStreamIdFilter(includedStreams));
    final Count.Builder builder = new Count.Builder().query(queryBuilder.toString()).addIndex(indices).addType(IndexMapping.TYPE_MESSAGE).setParameter(Parameters.IGNORE_UNAVAILABLE, true);
    final CountResult result = JestUtils.execute(jestClient, builder.build(), () -> "Unable to count documents of index.");
    return result.getCount().longValue();
}
Also used : FilterAggregationBuilder(org.graylog.shaded.elasticsearch6.org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder) BoolQueryBuilder(org.graylog.shaded.elasticsearch6.org.elasticsearch.index.query.BoolQueryBuilder) SearchSourceBuilder(org.graylog.shaded.elasticsearch6.org.elasticsearch.search.builder.SearchSourceBuilder) Count(io.searchbox.core.Count) CountResult(io.searchbox.core.CountResult) SearchSourceBuilder(org.graylog.shaded.elasticsearch6.org.elasticsearch.search.builder.SearchSourceBuilder)

Example 3 with CountResult

use of io.searchbox.core.CountResult in project dq-easy-cloud by dq-open-cloud.

the class TransportClient method count.

/**
 * Count文档
 *
 * @throws Exception
 */
@Test
public void count() throws Exception {
    String[] name = new String[] { "T:o\"m-", "Jerry" };
    String from = "2016-09-01T00:00:00";
    String to = "2016-10-01T00:00:00";
    SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
    QueryBuilder queryBuilder = QueryBuilders.boolQuery().must(QueryBuilders.termsQuery("name", name)).must(QueryBuilders.rangeQuery("birth").gte(from).lte(to));
    searchSourceBuilder.query(queryBuilder);
    String query = searchSourceBuilder.toString();
    System.out.println(query);
    Count count = new Count.Builder().addIndex(indexName).addType(typeName).query(query).build();
    CountResult results = jestClient.execute(count);
    Double counts = results.getCount();
    System.out.println("Count:" + counts);
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) HighlightBuilder(org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) Count(io.searchbox.core.Count) CountResult(io.searchbox.core.CountResult) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder) Test(org.junit.Test)

Aggregations

Count (io.searchbox.core.Count)3 CountResult (io.searchbox.core.CountResult)3 GsonBuilder (com.google.gson.GsonBuilder)1 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)1 SearchSourceBuilder (org.elasticsearch.search.builder.SearchSourceBuilder)1 HighlightBuilder (org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder)1 BoolQueryBuilder (org.graylog.shaded.elasticsearch6.org.elasticsearch.index.query.BoolQueryBuilder)1 FilterAggregationBuilder (org.graylog.shaded.elasticsearch6.org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder)1 SearchSourceBuilder (org.graylog.shaded.elasticsearch6.org.elasticsearch.search.builder.SearchSourceBuilder)1 Test (org.junit.Test)1