public static long getIndexCount(Client client, MongoDBRiverDefinition definition) { if (client.admin().indices().prepareExists(definition.getIndexName()).get().isExists()) { if (definition.isImportAllCollections()) { return client.prepareCount(definition.getIndexName()).execute().actionGet().getCount(); } else { if (client.admin().indices().prepareTypesExists(definition.getIndexName()).setTypes(definition.getTypeName()).get() .isExists()) { return client.prepareCount(definition.getIndexName()).setTypes(definition.getTypeName()).get().getCount(); } } } return 0; }
protected CountResponse count(String collectionName, QueryBuilder query) { return getClient().prepareCount() .setTypes(collectionName) .setQuery(query) .execute() .actionGet(initTimeout); }
protected CountResponse count(String collectionName, QueryBuilder query) { return getClient().prepareCount() .setTypes(collectionName) .setQuery(query) .execute() .actionGet(initTimeout); }
public int size() { MatchAllQueryBuilder query = QueryBuilders.matchAllQuery(); CountResponse response = client.prepareCount(index).setTypes(type).setQuery(query).execute().actionGet(); return MathUtil.longToInt(response.getCount()); }
@Override public <T> long count(Class<T> clazz, QueryBuilder query) { String indexName = getIndexForType(clazz); String typeName = MappingBuilder.indexTypeFromClass(clazz); CountRequestBuilder countRequestBuilder = getClient().prepareCount(indexName).setTypes(typeName); if (query != null) { countRequestBuilder.setQuery(query); } return countRequestBuilder.execute().actionGet().getCount(); }
public int count(String string) { QueryBuilder query = QueryBuilders.queryString(string).defaultOperator(Operator.AND); CountResponse response = client.prepareCount(index).setTypes(type).setQuery(query).execute().actionGet(); return MathUtil.longToInt(response.getCount()); }
@Override public <T> long count(SearchQuery query, Class<T> clazz) { ElasticsearchPersistentEntity<T> persistentEntity = getPersistentEntityFor(clazz); CountRequestBuilder countRequestBuilder = client.prepareCount(persistentEntity.getIndexName()) .setTypes(persistentEntity.getIndexType()); if(query.getQuery() != null){ countRequestBuilder.setQuery(query.getQuery()); } return countRequestBuilder.execute().actionGet().count(); }