use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchResponse in project elasticsearch by elastic.
the class SearchScrollWithFailingNodesIT method testScanScrollWithShardExceptions.
public void testScanScrollWithShardExceptions() throws Exception {
internalCluster().startNode();
internalCluster().startNode();
assertAcked(prepareCreate("test").setSettings(Settings.builder().put(indexSettings()).put(ShardsLimitAllocationDecider.INDEX_TOTAL_SHARDS_PER_NODE_SETTING.getKey(), 1)));
List<IndexRequestBuilder> writes = new ArrayList<>();
for (int i = 0; i < 100; i++) {
writes.add(client().prepareIndex("test", "type1").setSource(jsonBuilder().startObject().field("field", i).endObject()));
}
indexRandom(false, writes);
refresh();
SearchResponse searchResponse = client().prepareSearch().setQuery(matchAllQuery()).setSize(10).setScroll(TimeValue.timeValueMinutes(1)).get();
assertAllSuccessful(searchResponse);
long numHits = 0;
do {
numHits += searchResponse.getHits().getHits().length;
searchResponse = client().prepareSearchScroll(searchResponse.getScrollId()).setScroll(TimeValue.timeValueMinutes(1)).get();
assertAllSuccessful(searchResponse);
} while (searchResponse.getHits().getHits().length > 0);
assertThat(numHits, equalTo(100L));
clearScroll("_all");
internalCluster().stopRandomNonMasterNode();
searchResponse = client().prepareSearch().setQuery(matchAllQuery()).setSize(10).setScroll(TimeValue.timeValueMinutes(1)).get();
assertThat(searchResponse.getSuccessfulShards(), lessThan(searchResponse.getTotalShards()));
numHits = 0;
int numberOfSuccessfulShards = searchResponse.getSuccessfulShards();
do {
numHits += searchResponse.getHits().getHits().length;
searchResponse = client().prepareSearchScroll(searchResponse.getScrollId()).setScroll(TimeValue.timeValueMinutes(1)).get();
assertThat(searchResponse.getSuccessfulShards(), equalTo(numberOfSuccessfulShards));
} while (searchResponse.getHits().getHits().length > 0);
assertThat(numHits, greaterThan(0L));
clearScroll(searchResponse.getScrollId());
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchResponse in project elasticsearch by elastic.
the class SearchQueryIT method testBoolQueryMinShouldMatchBiggerThanNumberOfShouldClauses.
public void testBoolQueryMinShouldMatchBiggerThanNumberOfShouldClauses() throws IOException {
createIndex("test");
client().prepareIndex("test", "type1", "1").setSource("field1", new String[] { "value1", "value2", "value3" }).get();
client().prepareIndex("test", "type1", "2").setSource("field2", "value1").get();
refresh();
BoolQueryBuilder boolQuery = boolQuery().must(termQuery("field1", "value1")).should(boolQuery().should(termQuery("field1", "value1")).should(termQuery("field1", "value2")).minimumShouldMatch(3));
SearchResponse searchResponse = client().prepareSearch().setQuery(boolQuery).get();
assertHitCount(searchResponse, 1L);
assertFirstHit(searchResponse, hasId("1"));
boolQuery = boolQuery().must(termQuery("field1", "value1")).should(boolQuery().should(termQuery("field1", "value1")).should(termQuery("field1", "value2")).minimumShouldMatch(1)).minimumShouldMatch(2);
searchResponse = client().prepareSearch().setQuery(boolQuery).get();
assertHitCount(searchResponse, 0L);
boolQuery = boolQuery().should(termQuery("field1", "value1")).should(boolQuery().should(termQuery("field1", "value1")).should(termQuery("field1", "value2")).minimumShouldMatch(3)).minimumShouldMatch(1);
searchResponse = client().prepareSearch().setQuery(boolQuery).get();
assertHitCount(searchResponse, 1L);
assertFirstHit(searchResponse, hasId("1"));
boolQuery = boolQuery().must(termQuery("field1", "value1")).must(boolQuery().should(termQuery("field1", "value1")).should(termQuery("field1", "value2")).minimumShouldMatch(3));
searchResponse = client().prepareSearch().setQuery(boolQuery).get();
assertHitCount(searchResponse, 0L);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchResponse in project elasticsearch by elastic.
the class SearchQueryIT method testSpecialRangeSyntaxInQueryString.
public void testSpecialRangeSyntaxInQueryString() {
createIndex("test");
client().prepareIndex("test", "type1", "1").setSource("str", "kimchy", "date", "2012-02-01", "num", 12).get();
client().prepareIndex("test", "type1", "2").setSource("str", "shay", "date", "2012-02-05", "num", 20).get();
refresh();
SearchResponse searchResponse = client().prepareSearch().setQuery(queryStringQuery("num:>19")).get();
assertHitCount(searchResponse, 1L);
assertFirstHit(searchResponse, hasId("2"));
searchResponse = client().prepareSearch().setQuery(queryStringQuery("num:>20")).get();
assertHitCount(searchResponse, 0L);
searchResponse = client().prepareSearch().setQuery(queryStringQuery("num:>=20")).get();
assertHitCount(searchResponse, 1L);
assertFirstHit(searchResponse, hasId("2"));
searchResponse = client().prepareSearch().setQuery(queryStringQuery("num:>11")).get();
assertHitCount(searchResponse, 2L);
searchResponse = client().prepareSearch().setQuery(queryStringQuery("num:<20")).get();
assertHitCount(searchResponse, 1L);
searchResponse = client().prepareSearch().setQuery(queryStringQuery("num:<=20")).get();
assertHitCount(searchResponse, 2L);
searchResponse = client().prepareSearch().setQuery(queryStringQuery("+num:>11 +num:<20")).get();
assertHitCount(searchResponse, 1L);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchResponse in project elasticsearch by elastic.
the class SearchQueryIT method testMultiMatchQueryZeroTermsQuery.
public void testMultiMatchQueryZeroTermsQuery() {
assertAcked(prepareCreate("test").addMapping("type1", "field1", "type=text,analyzer=classic", "field2", "type=text,analyzer=classic"));
client().prepareIndex("test", "type1", "1").setSource("field1", "value1", "field2", "value2").get();
client().prepareIndex("test", "type1", "2").setSource("field1", "value3", "field2", "value4").get();
refresh();
BoolQueryBuilder boolQuery = boolQuery().must(multiMatchQuery("a", "field1", "field2").zeroTermsQuery(MatchQuery.ZeroTermsQuery.NONE)).must(// Fields are ORed together
multiMatchQuery("value1", "field1", "field2").zeroTermsQuery(MatchQuery.ZeroTermsQuery.NONE));
SearchResponse searchResponse = client().prepareSearch().setQuery(boolQuery).get();
assertHitCount(searchResponse, 0L);
boolQuery = boolQuery().must(multiMatchQuery("a", "field1", "field2").zeroTermsQuery(MatchQuery.ZeroTermsQuery.ALL)).must(multiMatchQuery("value4", "field1", "field2").zeroTermsQuery(MatchQuery.ZeroTermsQuery.ALL));
searchResponse = client().prepareSearch().setQuery(boolQuery).get();
assertHitCount(searchResponse, 1L);
boolQuery = boolQuery().must(multiMatchQuery("a", "field1").zeroTermsQuery(MatchQuery.ZeroTermsQuery.ALL));
searchResponse = client().prepareSearch().setQuery(boolQuery).get();
assertHitCount(searchResponse, 2L);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchResponse in project elasticsearch by elastic.
the class SearchQueryIT method testBasicQueryById.
public void testBasicQueryById() throws Exception {
createIndex("test");
client().prepareIndex("test", "type1", "1").setSource("field1", "value1").get();
client().prepareIndex("test", "type2", "2").setSource("field1", "value2").get();
refresh();
SearchResponse searchResponse = client().prepareSearch().setQuery(idsQuery("type1", "type2").addIds("1", "2")).get();
assertHitCount(searchResponse, 2L);
assertThat(searchResponse.getHits().getHits().length, equalTo(2));
searchResponse = client().prepareSearch().setQuery(idsQuery().addIds("1")).get();
assertHitCount(searchResponse, 1L);
assertThat(searchResponse.getHits().getHits().length, equalTo(1));
searchResponse = client().prepareSearch().setQuery(idsQuery().addIds("1", "2")).get();
assertHitCount(searchResponse, 2L);
assertThat(searchResponse.getHits().getHits().length, equalTo(2));
searchResponse = client().prepareSearch().setQuery(idsQuery("type1").addIds("1", "2")).get();
assertHitCount(searchResponse, 1L);
assertThat(searchResponse.getHits().getHits().length, equalTo(1));
searchResponse = client().prepareSearch().setQuery(idsQuery(Strings.EMPTY_ARRAY).addIds("1")).get();
assertHitCount(searchResponse, 1L);
assertThat(searchResponse.getHits().getHits().length, equalTo(1));
searchResponse = client().prepareSearch().setQuery(idsQuery("type1", "type2", "type3").addIds("1", "2", "3", "4")).get();
assertHitCount(searchResponse, 2L);
assertThat(searchResponse.getHits().getHits().length, equalTo(2));
}
Aggregations