Search in sources :

Example 36 with QueryBuilder

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.index.query.QueryBuilder in project elasticsearch by elastic.

the class RandomQueryGenerator method randomIDsQuery.

private static QueryBuilder randomIDsQuery() {
    QueryBuilder q = QueryBuilders.idsQuery();
    int numIDs = randomInt(100);
    for (int i = 0; i < numIDs; i++) {
        ((IdsQueryBuilder) q).addIds(String.valueOf(randomInt()));
    }
    if (randomBoolean()) {
        ((IdsQueryBuilder) q).boost(randomFloat());
    }
    return q;
}
Also used : IdsQueryBuilder(org.elasticsearch.index.query.IdsQueryBuilder) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) IdsQueryBuilder(org.elasticsearch.index.query.IdsQueryBuilder) RangeQueryBuilder(org.elasticsearch.index.query.RangeQueryBuilder) DisMaxQueryBuilder(org.elasticsearch.index.query.DisMaxQueryBuilder) CommonTermsQueryBuilder(org.elasticsearch.index.query.CommonTermsQueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) FuzzyQueryBuilder(org.elasticsearch.index.query.FuzzyQueryBuilder)

Example 37 with QueryBuilder

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.index.query.QueryBuilder in project elasticsearch by elastic.

the class RandomQueryGenerator method randomCommonTermsQuery.

private static QueryBuilder randomCommonTermsQuery(List<String> fields, int numDocs) {
    int numTerms = randomInt(numDocs);
    QueryBuilder q = QueryBuilders.commonTermsQuery(randomField(fields), randomQueryString(numTerms));
    if (randomBoolean()) {
        ((CommonTermsQueryBuilder) q).boost(randomFloat());
    }
    if (randomBoolean()) {
        ((CommonTermsQueryBuilder) q).cutoffFrequency(randomFloat());
    }
    if (randomBoolean()) {
        ((CommonTermsQueryBuilder) q).highFreqMinimumShouldMatch(Integer.toString(randomInt(numTerms))).highFreqOperator(randomBoolean() ? Operator.AND : Operator.OR);
    }
    if (randomBoolean()) {
        ((CommonTermsQueryBuilder) q).lowFreqMinimumShouldMatch(Integer.toString(randomInt(numTerms))).lowFreqOperator(randomBoolean() ? Operator.AND : Operator.OR);
    }
    return q;
}
Also used : QueryBuilder(org.elasticsearch.index.query.QueryBuilder) IdsQueryBuilder(org.elasticsearch.index.query.IdsQueryBuilder) RangeQueryBuilder(org.elasticsearch.index.query.RangeQueryBuilder) DisMaxQueryBuilder(org.elasticsearch.index.query.DisMaxQueryBuilder) CommonTermsQueryBuilder(org.elasticsearch.index.query.CommonTermsQueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) FuzzyQueryBuilder(org.elasticsearch.index.query.FuzzyQueryBuilder) CommonTermsQueryBuilder(org.elasticsearch.index.query.CommonTermsQueryBuilder)

Example 38 with QueryBuilder

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.index.query.QueryBuilder in project elasticsearch by elastic.

the class RandomQueryGenerator method randomDisMaxQuery.

private static QueryBuilder randomDisMaxQuery(List<String> stringFields, List<String> numericFields, int numDocs, int depth) {
    QueryBuilder q = QueryBuilders.disMaxQuery();
    int numClauses = randomIntBetween(1, 10);
    for (int i = 0; i < numClauses; i++) {
        ((DisMaxQueryBuilder) q).add(randomQueryBuilder(stringFields, numericFields, numDocs, depth - 1));
    }
    if (randomBoolean()) {
        ((DisMaxQueryBuilder) q).boost(randomFloat());
    }
    if (randomBoolean()) {
        ((DisMaxQueryBuilder) q).tieBreaker(randomFloat());
    }
    return q;
}
Also used : DisMaxQueryBuilder(org.elasticsearch.index.query.DisMaxQueryBuilder) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) IdsQueryBuilder(org.elasticsearch.index.query.IdsQueryBuilder) RangeQueryBuilder(org.elasticsearch.index.query.RangeQueryBuilder) DisMaxQueryBuilder(org.elasticsearch.index.query.DisMaxQueryBuilder) CommonTermsQueryBuilder(org.elasticsearch.index.query.CommonTermsQueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) FuzzyQueryBuilder(org.elasticsearch.index.query.FuzzyQueryBuilder)

Example 39 with QueryBuilder

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.index.query.QueryBuilder in project elasticsearch by elastic.

the class RandomQueryGenerator method randomBoolQuery.

private static QueryBuilder randomBoolQuery(List<String> stringFields, List<String> numericFields, int numDocs, int depth) {
    QueryBuilder q = QueryBuilders.boolQuery();
    int numClause = randomIntBetween(0, 5);
    for (int i = 0; i < numClause; i++) {
        ((BoolQueryBuilder) q).must(randomQueryBuilder(stringFields, numericFields, numDocs, depth - 1));
    }
    numClause = randomIntBetween(0, 5);
    for (int i = 0; i < numClause; i++) {
        ((BoolQueryBuilder) q).should(randomQueryBuilder(stringFields, numericFields, numDocs, depth - 1));
    }
    numClause = randomIntBetween(0, 5);
    for (int i = 0; i < numClause; i++) {
        ((BoolQueryBuilder) q).mustNot(randomQueryBuilder(stringFields, numericFields, numDocs, depth - 1));
    }
    return q;
}
Also used : BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) IdsQueryBuilder(org.elasticsearch.index.query.IdsQueryBuilder) RangeQueryBuilder(org.elasticsearch.index.query.RangeQueryBuilder) DisMaxQueryBuilder(org.elasticsearch.index.query.DisMaxQueryBuilder) CommonTermsQueryBuilder(org.elasticsearch.index.query.CommonTermsQueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) FuzzyQueryBuilder(org.elasticsearch.index.query.FuzzyQueryBuilder)

Example 40 with QueryBuilder

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.index.query.QueryBuilder in project elasticsearch by elastic.

the class QueryProfilerIT method testCollapsingBool.

/**
     * Tests a series of three nested boolean queries with a single "leaf" match query.
     * The rewrite process will "collapse" this down to a single bool, so this tests to make sure
     * nothing catastrophic happens during that fairly substantial rewrite
     */
public void testCollapsingBool() throws Exception {
    createIndex("test");
    ensureGreen();
    int numDocs = randomIntBetween(100, 150);
    IndexRequestBuilder[] docs = new IndexRequestBuilder[numDocs];
    for (int i = 0; i < numDocs; i++) {
        docs[i] = client().prepareIndex("test", "type1", String.valueOf(i)).setSource("field1", English.intToEnglish(i), "field2", i);
    }
    indexRandom(true, docs);
    refresh();
    QueryBuilder q = QueryBuilders.boolQuery().must(QueryBuilders.boolQuery().must(QueryBuilders.boolQuery().must(QueryBuilders.matchQuery("field1", "one"))));
    logger.info("Query: {}", q);
    SearchResponse resp = client().prepareSearch().setQuery(q).setProfile(true).setSearchType(SearchType.QUERY_THEN_FETCH).execute().actionGet();
    assertNotNull("Profile response element should not be null", resp.getProfileResults());
    assertThat("Profile response should not be an empty array", resp.getProfileResults().size(), not(0));
    for (Map.Entry<String, ProfileShardResult> shardResult : resp.getProfileResults().entrySet()) {
        for (QueryProfileShardResult searchProfiles : shardResult.getValue().getQueryProfileResults()) {
            for (ProfileResult result : searchProfiles.getQueryResults()) {
                assertNotNull(result.getQueryName());
                assertNotNull(result.getLuceneDescription());
                assertThat(result.getTime(), greaterThan(0L));
                assertNotNull(result.getTimeBreakdown());
            }
            CollectorResult result = searchProfiles.getCollectorResult();
            assertThat(result.getName(), not(isEmptyOrNullString()));
            assertThat(result.getTime(), greaterThan(0L));
        }
    }
}
Also used : IndexRequestBuilder(org.elasticsearch.action.index.IndexRequestBuilder) ProfileResult(org.elasticsearch.search.profile.ProfileResult) RandomQueryGenerator.randomQueryBuilder(org.elasticsearch.search.profile.query.RandomQueryGenerator.randomQueryBuilder) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) Map(java.util.Map) MultiSearchResponse(org.elasticsearch.action.search.MultiSearchResponse) SearchResponse(org.elasticsearch.action.search.SearchResponse) ProfileShardResult(org.elasticsearch.search.profile.ProfileShardResult)

Aggregations

QueryBuilder (org.elasticsearch.index.query.QueryBuilder)371 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)245 Test (org.testng.annotations.Test)156 DynamicEntity (org.molgenis.data.support.DynamicEntity)137 SearchResponse (org.elasticsearch.action.search.SearchResponse)58 QueryImpl (org.molgenis.data.support.QueryImpl)36 Map (java.util.Map)32 ArrayList (java.util.ArrayList)30 Test (org.junit.Test)30 SearchSourceBuilder (org.elasticsearch.search.builder.SearchSourceBuilder)29 HashMap (java.util.HashMap)27 MatchAllQueryBuilder (org.elasticsearch.index.query.MatchAllQueryBuilder)27 RangeQueryBuilder (org.elasticsearch.index.query.RangeQueryBuilder)27 IOException (java.io.IOException)23 SearchHit (org.elasticsearch.search.SearchHit)22 AbstractQueryBuilder (org.elasticsearch.index.query.AbstractQueryBuilder)19 TermQueryBuilder (org.elasticsearch.index.query.TermQueryBuilder)19 List (java.util.List)17 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)17 IndexRequestBuilder (org.elasticsearch.action.index.IndexRequestBuilder)15