本文整理汇总了Java中org.elasticsearch.action.count.CountResponse.getCount方法的典型用法代码示例。如果您正苦于以下问题:Java CountResponse.getCount方法的具体用法?Java CountResponse.getCount怎么用?Java CountResponse.getCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.action.count.CountResponse
的用法示例。
在下文中一共展示了CountResponse.getCount方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: countRequest
import org.elasticsearch.action.count.CountResponse; //导入方法依赖的package包/类
/**
* With retry
*/
public static long countRequest(final String index, final QueryBuilder query, final String... types) {
CountResponse response = withRetry(new ElasticsearchWithRetry<CountResponse>() {
public CountResponse call(Client client) throws NoNodeAvailableException {
CountRequestBuilder request_builder = new CountRequestBuilder(client);
request_builder.setIndices(index);
request_builder.setTypes(types);
request_builder.setQuery(query);
return request_builder.execute().actionGet();
}
});
if (response == null) {
return 0;
}
return response.getCount();
}
示例2: getPendingDocuments
import org.elasticsearch.action.count.CountResponse; //导入方法依赖的package包/类
@Override
public int getPendingDocuments() {
try {
CountResponse response = client.prepareCount(indexName)
.setQuery(filteredQuery(matchAllQuery(), orFilter(
missingFilter(SearchService.FIELD_INDEXED),
termFilter(SearchService.FIELD_INDEXED, false))))
.execute()
.actionGet();
return (int) response.getCount();
} catch (Exception e) {
getLog().error("Problem getting pending docs for index builder [" + getName() + "]", e);
}
return 0;
}
示例3: count
import org.elasticsearch.action.count.CountResponse; //导入方法依赖的package包/类
/**
*
* @return number of all Assets in the index.
*/
@Override
public long count() {
CountResponse countResponse = client.prepareCount(indexName)
.setQuery(termQuery("_type", documentType))
.execute()
.actionGet();
return countResponse.getCount();
}
示例4: getNDocs
import org.elasticsearch.action.count.CountResponse; //导入方法依赖的package包/类
@Override
public int getNDocs() {
assureIndex();
CountResponse response = client.prepareCount(indexName)
.setQuery(filteredQuery(matchAllQuery(),termFilter(SearchService.FIELD_INDEXED, true)))
.execute()
.actionGet();
return (int) response.getCount();
}
示例5: count
import org.elasticsearch.action.count.CountResponse; //导入方法依赖的package包/类
public long count(BaseQueryBuilder xqb) throws Exception {
CountResponse response =
esclient.client.prepareCount(index).
setQuery(xqb).
execute().actionGet();
return response.getCount();
}
示例6: waitForUpdateCompletion
import org.elasticsearch.action.count.CountResponse; //导入方法依赖的package包/类
@SneakyThrows({InterruptedException.class})
protected void waitForUpdateCompletion(int inv) {
while(true){
CountRequestBuilder countRequestBuilder = client.prepareCount (dummyIndexName (getNUMROWS(), getNUMCOLS(), inv)).setTypes (getDocumentType ());
CountResponse countResponse = countRequestBuilder.execute ().actionGet ();
if(countResponse.getCount ()==getNUMROWS ())
break;
Thread.sleep (500);
}
}
示例7: waitForUpdateCompletion
import org.elasticsearch.action.count.CountResponse; //导入方法依赖的package包/类
@SneakyThrows({InterruptedException.class})
protected void waitForUpdateCompletion() {
while(true){
CountRequestBuilder countRequestBuilder = client.prepareCount (adminHelper.dummyName (getNUMROWS(), getNUMCOLS())).setTypes (getDocumentType ());
CountResponse countResponse = countRequestBuilder.execute ().actionGet ();
if(countResponse.getCount ()==getNUMROWS ())
break;
Thread.sleep (500);
}
}
示例8: getDocumentCount
import org.elasticsearch.action.count.CountResponse; //导入方法依赖的package包/类
public long getDocumentCount() throws Exception {
try (Client client = getClient()) {
client.admin().indices().refresh(new RefreshRequest(INDEX_NAME)).actionGet();
ActionFuture<CountResponse> response = client.count(new CountRequest(INDEX_NAME).types(DOCUMENT_TYPE));
CountResponse countResponse = response.get();
return countResponse.getCount();
}
}
示例9: handle
import org.elasticsearch.action.count.CountResponse; //导入方法依赖的package包/类
@Override
public void handle(final Long timerId) {
//
// Generate some test events
//
for (int i = 0; i < 100; i++) {
JsonObject event = EventCreator.createBatch("Elasticsearch");
vertx.eventBus().publish(EVENT_SRC_ADDRESS, event);
}
//
// Verify index creation
//
boolean exists = m_client.admin()
.indices()
.exists(new IndicesExistsRequest(INDEX_SELECTOR))
.actionGet()
.isExists();
if (exists) {
CountResponse countResp = m_client.prepareCount(INDEX_SELECTOR)
.setQuery(termQuery("_type", INDEX_TYPE))
.execute()
.actionGet();
long count = countResp.getCount();
if (count >= INDEX_COUNT) {
//
// Success
//
m_logger.info("Created {} indexes", count);
VertxAssert.testComplete();
} else {
if (m_iter++ > m_maxIterCount) {
Assert.assertEquals("Failed to create " + INDEX_COUNT
+ " indexes", INDEX_COUNT, countResp.getCount());
// Stop test
VertxAssert.testComplete();
}
}
}
}
示例10: getPathsWithStats
import org.elasticsearch.action.count.CountResponse; //导入方法依赖的package包/类
public String getPathsWithStats(String tenant, String wildcard) throws TooMuchDataExpectedException {
String regEx = WildcardUtil.getPathsRegExFromWildcard(wildcard);
SearchResponse response = client.prepareSearch(indexConfiguration.getIndex())
.setScroll(new TimeValue(indexConfiguration.getTimeout()))
.setSize(indexConfiguration.getScroll())
.setQuery(QueryBuilders.filteredQuery(
QueryBuilders.regexpQuery("path", regEx),
FilterBuilders.termFilter("tenant", tenant)))
.addField("path")
.execute().actionGet();
// if total hits exceeds maximum - abort right away returning empty array
if (response.getHits().totalHits() > indexConfiguration.getMaxPaths()) {
logger.debug("Total number of paths exceeds the limit: " + response.getHits().totalHits());
throw new TooMuchDataExpectedException("Total number of paths exceeds the limit: " + response.getHits().totalHits() + " (the limit is " + indexConfiguration.getMaxPaths() + ")");
}
List<String> paths = new ArrayList<>();
while (response.getHits().getHits().length > 0) {
for (SearchHit hit : response.getHits()) {
paths.add(String.valueOf(hit.field("path").getValue()));
}
response = client.prepareSearchScroll(response.getScrollId())
.setScroll(new TimeValue(indexConfiguration.getTimeout()))
.execute().actionGet();
}
Collections.sort(paths);
// we got the paths. Now let's get the counts
List<String> result = new ArrayList<>();
for (String path : paths) {
CountResponse countResponse = client.prepareCount(indexConfiguration.getIndex())
.setQuery(QueryBuilders.filteredQuery(
QueryBuilders.regexpQuery("path", path + "\\..*"),
FilterBuilders.boolFilter()
.must(FilterBuilders.termFilter("tenant", tenant))
.must(FilterBuilders.termFilter("leaf", true))))
.execute().actionGet();
long count = countResponse.getCount();
result.add("{\"path\": \"" + path + "\",\"count\":" + countResponse.getCount() + "}");
}
return "[" + joiner.join(result) + "]";
}
示例11: count
import org.elasticsearch.action.count.CountResponse; //导入方法依赖的package包/类
@Override
public long count(Set<String> types, String query, Set<String> filterIds, EzSecurityToken userToken)
throws TException {
final Stopwatch watch = LoggingUtils.createStopWatch();
CountRequestBuilder requestBuilder = client.prepareCount(indexName);
final VisibilityFilterConfig filterConfig =
new VisibilityFilterConfig(VISIBILITY_FIELD, EnumSet.of(Permission.DISCOVER));
final ScriptFilterBuilder visibilityFilter = getVisibilityFilter(userToken, filterConfig);
if (!types.isEmpty()) {
requestBuilder = requestBuilder.setTypes(types.toArray(new String[types.size()]));
}
if (!filterIds.isEmpty()) {
if (StringUtils.isNotEmpty(query)) {
requestBuilder = requestBuilder.setQuery(
QueryBuilders.filteredQuery(
QueryBuilders.boolQuery().must(parseQuery(query)).must(
QueryBuilders.idsQuery().addIds(
filterIds.toArray(new String[filterIds.size()]))), visibilityFilter));
} else {
requestBuilder = requestBuilder.setQuery(
QueryBuilders.filteredQuery(
QueryBuilders.idsQuery().addIds(filterIds.toArray(new String[filterIds.size()])),
visibilityFilter));
}
} else if (StringUtils.isNotEmpty(query)) {
requestBuilder = requestBuilder.setQuery(QueryBuilders.filteredQuery(parseQuery(query), visibilityFilter));
} else {
requestBuilder = requestBuilder.setQuery(
QueryBuilders.filteredQuery(
QueryBuilders.matchAllQuery(), visibilityFilter));
}
final CountResponse response = requestBuilder.get();
LoggingUtils.stopAndLogStopWatch(logger, watch, "Count");
return response.getCount();
}
示例12: testAddAndRemoveNodes
import org.elasticsearch.action.count.CountResponse; //导入方法依赖的package包/类
@Test
public void testAddAndRemoveNodes() throws InterruptedException {
Thread.sleep(200); // allow river to start
String name = UUID.randomUUID().toString();
// add node to neo4j
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("name", name);
Transaction tx = db.beginTx();
ArrayList<String> labels = new ArrayList<String>();
org.neo4j.graphdb.Node n = db.createNode(map, labels);
tx.success();
CountResponse resp = null;
int k = 0;
while (k++ < 100) {
Thread.sleep(1000); // time for poller to index
refreshIndex();
logger.debug("Count request [index={}, type={}, name={}]", new Object[]{index, type, name});
resp = node.client().count(countRequest(index).types(type).source(queryString(name).defaultField("name").toString())).actionGet();
if (1 == resp.getCount())
break;
}
assertEquals(1, resp.getCount());
db.remove(n);
k = 0;
while (k++ < 100) {
Thread.sleep(1000); // time for poller to index
refreshIndex();
logger.debug("Count request [index={}, type={}, name={}]", new Object[]{index, type, name});
resp = node.client().count(countRequest(index).types(type).source(queryString(name).defaultField("name").toString())).actionGet();
if (0 == resp.getCount())
break;
}
assertEquals(0, resp.getCount());
shutdown();
}
示例13: getCount
import org.elasticsearch.action.count.CountResponse; //导入方法依赖的package包/类
protected long getCount(final String index, final String type) {
logger.debug("getCount()");
esSetup.client().admin().indices().refresh(new RefreshRequest()).actionGet();
final CountResponse count = esSetup.client().count(new CountRequest(index).types(type)).actionGet();
return count.getCount();
}