Search in sources :

Example 6 with SearchType

use of org.elasticsearch.action.search.SearchType in project elasticsearch by elastic.

the class SearchScrollIT method testDeepScrollingDoesNotBlowUp.

/**
     * Tests that we use an optimization shrinking the batch to the size of the shard. Thus the Integer.MAX_VALUE window doesn't OOM us.
     */
public void testDeepScrollingDoesNotBlowUp() throws Exception {
    client().prepareIndex("index", "type", "1").setSource("field", "value").setRefreshPolicy(IMMEDIATE).execute().get();
    /*
         * Disable the max result window setting for this test because it'll reject the search's unreasonable batch size. We want
         * unreasonable batch sizes to just OOM.
         */
    client().admin().indices().prepareUpdateSettings("index").setSettings(Settings.builder().put(IndexSettings.MAX_RESULT_WINDOW_SETTING.getKey(), Integer.MAX_VALUE)).get();
    for (SearchType searchType : SearchType.values()) {
        SearchRequestBuilder builder = client().prepareSearch("index").setSearchType(searchType).setQuery(QueryBuilders.matchAllQuery()).setSize(Integer.MAX_VALUE).setScroll("1m");
        SearchResponse response = builder.execute().actionGet();
        try {
            ElasticsearchAssertions.assertHitCount(response, 1L);
        } finally {
            String scrollId = response.getScrollId();
            if (scrollId != null) {
                clearScroll(scrollId);
            }
        }
    }
}
Also used : SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) SearchType(org.elasticsearch.action.search.SearchType) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 7 with SearchType

use of org.elasticsearch.action.search.SearchType in project elasticsearch by elastic.

the class ChildQuerySearchIT method testSimpleQueryRewrite.

public void testSimpleQueryRewrite() throws Exception {
    assertAcked(prepareCreate("test").addMapping("parent", "p_field", "type=keyword").addMapping("child", "_parent", "type=parent", "c_field", "type=keyword"));
    ensureGreen();
    // index simple data
    int childId = 0;
    for (int i = 0; i < 10; i++) {
        String parentId = String.format(Locale.ROOT, "p%03d", i);
        client().prepareIndex("test", "parent", parentId).setSource("p_field", parentId).get();
        int j = childId;
        for (; j < childId + 50; j++) {
            String childUid = String.format(Locale.ROOT, "c%03d", j);
            client().prepareIndex("test", "child", childUid).setSource("c_field", childUid).setParent(parentId).get();
        }
        childId = j;
    }
    refresh();
    SearchType[] searchTypes = new SearchType[] { SearchType.QUERY_THEN_FETCH, SearchType.DFS_QUERY_THEN_FETCH };
    for (SearchType searchType : searchTypes) {
        SearchResponse searchResponse = client().prepareSearch("test").setSearchType(searchType).setQuery(hasChildQuery("child", prefixQuery("c_field", "c"), ScoreMode.Max)).addSort("p_field", SortOrder.ASC).setSize(5).get();
        assertNoFailures(searchResponse);
        assertThat(searchResponse.getHits().getTotalHits(), equalTo(10L));
        assertThat(searchResponse.getHits().getHits()[0].getId(), equalTo("p000"));
        assertThat(searchResponse.getHits().getHits()[1].getId(), equalTo("p001"));
        assertThat(searchResponse.getHits().getHits()[2].getId(), equalTo("p002"));
        assertThat(searchResponse.getHits().getHits()[3].getId(), equalTo("p003"));
        assertThat(searchResponse.getHits().getHits()[4].getId(), equalTo("p004"));
        searchResponse = client().prepareSearch("test").setSearchType(searchType).setQuery(hasParentQuery("parent", prefixQuery("p_field", "p"), true)).addSort("c_field", SortOrder.ASC).setSize(5).get();
        assertNoFailures(searchResponse);
        assertThat(searchResponse.getHits().getTotalHits(), equalTo(500L));
        assertThat(searchResponse.getHits().getHits()[0].getId(), equalTo("c000"));
        assertThat(searchResponse.getHits().getHits()[1].getId(), equalTo("c001"));
        assertThat(searchResponse.getHits().getHits()[2].getId(), equalTo("c002"));
        assertThat(searchResponse.getHits().getHits()[3].getId(), equalTo("c003"));
        assertThat(searchResponse.getHits().getHits()[4].getId(), equalTo("c004"));
    }
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) SearchType(org.elasticsearch.action.search.SearchType) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Aggregations

SearchType (org.elasticsearch.action.search.SearchType)7 SearchResponse (org.elasticsearch.action.search.SearchResponse)2 IntHashSet (com.carrotsearch.hppc.IntHashSet)1 IOException (java.io.IOException)1 AbstractList (java.util.AbstractList)1 ArrayList (java.util.ArrayList)1 Callable (java.util.concurrent.Callable)1 Future (java.util.concurrent.Future)1 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)1 Term (org.apache.lucene.index.Term)1 MinDocQuery (org.apache.lucene.queries.MinDocQuery)1 BooleanQuery (org.apache.lucene.search.BooleanQuery)1 Collector (org.apache.lucene.search.Collector)1 ConstantScoreQuery (org.apache.lucene.search.ConstantScoreQuery)1 FieldDoc (org.apache.lucene.search.FieldDoc)1 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)1 MultiCollector (org.apache.lucene.search.MultiCollector)1 Query (org.apache.lucene.search.Query)1 ScoreDoc (org.apache.lucene.search.ScoreDoc)1 Sort (org.apache.lucene.search.Sort)1