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();
}
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();
}
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);
}
Aggregations