Search in sources :

Example 91 with QueryBuilder

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

the class QueryProfilerIT method testDisMaxRange.

public void testDisMaxRange() 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.disMaxQuery().boost(0.33703882f).add(QueryBuilders.rangeQuery("field2").from(null).to(73).includeLower(true).includeUpper(true));
    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)

Example 92 with QueryBuilder

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

the class QueryProfilerIT method testProfileQuery.

/**
     * This test simply checks to make sure nothing crashes.  Test indexes 100-150 documents,
     * constructs 20-100 random queries and tries to profile them
     */
public void testProfileQuery() 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);
    }
    List<String> stringFields = Arrays.asList("field1");
    List<String> numericFields = Arrays.asList("field2");
    indexRandom(true, docs);
    refresh();
    int iters = between(20, 100);
    for (int i = 0; i < iters; i++) {
        QueryBuilder q = randomQueryBuilder(stringFields, numericFields, numDocs, 3);
        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> shard : resp.getProfileResults().entrySet()) {
            for (QueryProfileShardResult searchProfiles : shard.getValue().getQueryProfileResults()) {
                for (ProfileResult result : searchProfiles.getQueryResults()) {
                    assertNotNull(result.getQueryName());
                    assertNotNull(result.getLuceneDescription());
                    assertThat(result.getTime(), greaterThan(0L));
                }
                CollectorResult result = searchProfiles.getCollectorResult();
                assertThat(result.getName(), not(isEmptyOrNullString()));
                assertThat(result.getTime(), greaterThan(0L));
            }
        }
    }
}
Also used : Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) RandomQueryGenerator.randomQueryBuilder(org.elasticsearch.search.profile.query.RandomQueryGenerator.randomQueryBuilder) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) MultiSearchResponse(org.elasticsearch.action.search.MultiSearchResponse) SearchResponse(org.elasticsearch.action.search.SearchResponse) IndexRequestBuilder(org.elasticsearch.action.index.IndexRequestBuilder) ProfileResult(org.elasticsearch.search.profile.ProfileResult) Map(java.util.Map) ProfileShardResult(org.elasticsearch.search.profile.ProfileShardResult)

Example 93 with QueryBuilder

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

the class QueryProfilerIT method testBoosting.

public void testBoosting() 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.boostingQuery(QueryBuilders.matchQuery("field1", "one"), QueryBuilders.matchQuery("field1", "two")).boost(randomFloat()).negativeBoost(randomFloat());
    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)

Example 94 with QueryBuilder

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

the class QueryProfilerIT method testRange.

public void testRange() 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.rangeQuery("field2").from(0).to(5);
    logger.info("Query: {}", q.toString());
    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)

Example 95 with QueryBuilder

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

the class AdjacencyMatrixTests method createTestAggregatorBuilder.

@Override
protected AdjacencyMatrixAggregationBuilder createTestAggregatorBuilder() {
    int size = randomIntBetween(1, 20);
    AdjacencyMatrixAggregationBuilder factory;
    Map<String, QueryBuilder> filters = new HashMap<>(size);
    for (String key : randomUnique(() -> randomAsciiOfLengthBetween(1, 20), size)) {
        filters.put(key, QueryBuilders.termQuery(randomAsciiOfLengthBetween(5, 20), randomAsciiOfLengthBetween(5, 20)));
    }
    factory = new AdjacencyMatrixAggregationBuilder(randomAsciiOfLengthBetween(1, 20), filters).separator(randomFrom("&", "+", "\t"));
    return factory;
}
Also used : AdjacencyMatrixAggregationBuilder(org.elasticsearch.search.aggregations.bucket.adjacency.AdjacencyMatrixAggregationBuilder) HashMap(java.util.HashMap) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) MatchNoneQueryBuilder(org.elasticsearch.index.query.MatchNoneQueryBuilder)

Aggregations

QueryBuilder (org.elasticsearch.index.query.QueryBuilder)161 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)51 SearchResponse (org.elasticsearch.action.search.SearchResponse)32 MatchAllQueryBuilder (org.elasticsearch.index.query.MatchAllQueryBuilder)25 Map (java.util.Map)22 ArrayList (java.util.ArrayList)19 AbstractQueryBuilder (org.elasticsearch.index.query.AbstractQueryBuilder)19 RangeQueryBuilder (org.elasticsearch.index.query.RangeQueryBuilder)19 MatchQueryBuilder (org.elasticsearch.index.query.MatchQueryBuilder)18 HashMap (java.util.HashMap)16 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)16 IndexRequestBuilder (org.elasticsearch.action.index.IndexRequestBuilder)14 HasParentQueryBuilder (org.elasticsearch.index.query.HasParentQueryBuilder)14 TermQueryBuilder (org.elasticsearch.index.query.TermQueryBuilder)14 FunctionScoreQueryBuilder (org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder)14 IOException (java.io.IOException)12 FessConfig (org.codelibs.fess.mylasta.direction.FessConfig)12 MultiSearchResponse (org.elasticsearch.action.search.MultiSearchResponse)11 XContentParser (org.elasticsearch.common.xcontent.XContentParser)11 BytesRef (org.apache.lucene.util.BytesRef)10