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);
}
}
}
}
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"));
}
}
Aggregations