Search in sources :

Example 16 with MatchAllQueryBuilder

use of org.elasticsearch.index.query.MatchAllQueryBuilder in project crate by crate.

the class PartitionedTableIntegrationTest method validateInsertPartitionedTable.

private void validateInsertPartitionedTable() {
    Set<String> indexUUIDs = new HashSet<>(3);
    String partitionName = new PartitionName("parted", Collections.singletonList(new BytesRef(String.valueOf(13959981214861L)))).asIndexName();
    assertThat(internalCluster().clusterService().state().metaData().hasIndex(partitionName), is(true));
    IndexMetaData indexMetaData = client().admin().cluster().prepareState().execute().actionGet().getState().metaData().indices().get(partitionName);
    indexUUIDs.add(indexMetaData.getIndexUUID());
    assertThat(indexMetaData.getAliases().get("parted"), notNullValue());
    assertThat(client().prepareSearch(partitionName).setTypes(Constants.DEFAULT_MAPPING_TYPE).setSize(0).setQuery(new MatchAllQueryBuilder()).execute().actionGet().getHits().totalHits(), is(1L));
    partitionName = new PartitionName("parted", Collections.singletonList(new BytesRef(String.valueOf(0L)))).asIndexName();
    assertThat(internalCluster().clusterService().state().metaData().hasIndex(partitionName), is(true));
    indexMetaData = client().admin().cluster().prepareState().execute().actionGet().getState().metaData().indices().get(partitionName);
    indexUUIDs.add(indexMetaData.getIndexUUID());
    assertThat(indexMetaData.getAliases().get("parted"), notNullValue());
    assertThat(client().prepareSearch(partitionName).setTypes(Constants.DEFAULT_MAPPING_TYPE).setSize(0).setQuery(new MatchAllQueryBuilder()).execute().actionGet().getHits().totalHits(), is(1L));
    List<BytesRef> nullList = new ArrayList<>();
    nullList.add(null);
    partitionName = new PartitionName("parted", nullList).asIndexName();
    assertThat(internalCluster().clusterService().state().metaData().hasIndex(partitionName), is(true));
    indexMetaData = client().admin().cluster().prepareState().execute().actionGet().getState().metaData().indices().get(partitionName);
    indexUUIDs.add(indexMetaData.getIndexUUID());
    assertThat(indexMetaData.getAliases().get("parted"), notNullValue());
    assertThat(client().prepareSearch(partitionName).setTypes(Constants.DEFAULT_MAPPING_TYPE).setSize(0).setQuery(new MatchAllQueryBuilder()).execute().actionGet().getHits().totalHits(), is(1L));
    assertThat(indexUUIDs.size(), is(3));
}
Also used : PartitionName(io.crate.metadata.PartitionName) BytesRef(org.apache.lucene.util.BytesRef) DocIndexMetaData(io.crate.metadata.doc.DocIndexMetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) MatchAllQueryBuilder(org.elasticsearch.index.query.MatchAllQueryBuilder)

Example 17 with MatchAllQueryBuilder

use of org.elasticsearch.index.query.MatchAllQueryBuilder in project incubator-sdap-mudrod by apache.

the class ESDriver method getDocCount.

public int getDocCount(String index, String... type) {
    MatchAllQueryBuilder search = QueryBuilders.matchAllQuery();
    String[] indexArr = new String[] { index };
    return this.getDocCount(indexArr, type, search);
}
Also used : MatchAllQueryBuilder(org.elasticsearch.index.query.MatchAllQueryBuilder)

Example 18 with MatchAllQueryBuilder

use of org.elasticsearch.index.query.MatchAllQueryBuilder in project presto by prestodb.

the class ElasticsearchQueryBuilder method buildSearchQuery.

public static QueryBuilder buildSearchQuery(ConnectorSession session, TupleDomain<ElasticsearchColumnHandle> constraint, Optional<String> query) {
    BoolQueryBuilder queryBuilder = new BoolQueryBuilder();
    if (constraint.getDomains().isPresent()) {
        for (Map.Entry<ElasticsearchColumnHandle, Domain> entry : constraint.getDomains().get().entrySet()) {
            ElasticsearchColumnHandle column = entry.getKey();
            Domain domain = entry.getValue();
            checkArgument(!domain.isNone(), "Unexpected NONE domain for %s", column.getName());
            if (!domain.isAll()) {
                queryBuilder.filter(new BoolQueryBuilder().must(buildPredicate(session, column.getName(), domain, column.getType())));
            }
        }
    }
    query.map(QueryStringQueryBuilder::new).ifPresent(queryBuilder::must);
    if (queryBuilder.hasClauses()) {
        return queryBuilder;
    }
    return new MatchAllQueryBuilder();
}
Also used : BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) Domain(com.facebook.presto.common.predicate.Domain) TupleDomain(com.facebook.presto.common.predicate.TupleDomain) Map(java.util.Map) MatchAllQueryBuilder(org.elasticsearch.index.query.MatchAllQueryBuilder)

Aggregations

MatchAllQueryBuilder (org.elasticsearch.index.query.MatchAllQueryBuilder)18 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)7 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)6 ArrayList (java.util.ArrayList)4 TermQueryBuilder (org.elasticsearch.index.query.TermQueryBuilder)4 Script (org.elasticsearch.script.Script)4 HashMap (java.util.HashMap)3 SearchResponse (org.elasticsearch.action.search.SearchResponse)3 MatchQueryBuilder (org.elasticsearch.index.query.MatchQueryBuilder)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 Map (java.util.Map)2 ParsingException (org.elasticsearch.common.ParsingException)2 XContentParser (org.elasticsearch.common.xcontent.XContentParser)2 AbstractQueryBuilder (org.elasticsearch.index.query.AbstractQueryBuilder)2 HasChildQueryBuilder (org.elasticsearch.index.query.HasChildQueryBuilder)2 HasParentQueryBuilder (org.elasticsearch.index.query.HasParentQueryBuilder)2 RangeQueryBuilder (org.elasticsearch.index.query.RangeQueryBuilder)2 TermsQueryBuilder (org.elasticsearch.index.query.TermsQueryBuilder)2 FilterFunctionBuilder (org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder.FilterFunctionBuilder)2 ElasticsearchAssertions.assertSearchResponse (org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)2