use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchResponse in project elasticsearch by elastic.
the class SearchQueryIT method testIdsQueryTestsIdIndexed.
public void testIdsQueryTestsIdIndexed() throws Exception {
assertAcked(client().admin().indices().prepareCreate("test"));
indexRandom(true, client().prepareIndex("test", "type1", "1").setSource("field1", "value1"), client().prepareIndex("test", "type1", "2").setSource("field1", "value2"), client().prepareIndex("test", "type1", "3").setSource("field1", "value3"));
SearchResponse searchResponse = client().prepareSearch().setQuery(constantScoreQuery(idsQuery("type1").addIds("1", "3"))).get();
assertHitCount(searchResponse, 2L);
assertSearchHits(searchResponse, "1", "3");
// no type
searchResponse = client().prepareSearch().setQuery(constantScoreQuery(idsQuery().addIds("1", "3"))).get();
assertHitCount(searchResponse, 2L);
assertSearchHits(searchResponse, "1", "3");
searchResponse = client().prepareSearch().setQuery(idsQuery("type1").addIds("1", "3")).get();
assertHitCount(searchResponse, 2L);
assertSearchHits(searchResponse, "1", "3");
// no type
searchResponse = client().prepareSearch().setQuery(idsQuery().addIds("1", "3")).get();
assertHitCount(searchResponse, 2L);
assertSearchHits(searchResponse, "1", "3");
searchResponse = client().prepareSearch().setQuery(idsQuery("type1").addIds("7", "10")).get();
assertHitCount(searchResponse, 0L);
// repeat..., with terms
searchResponse = client().prepareSearch().setTypes("type1").setQuery(constantScoreQuery(termsQuery("_id", "1", "3"))).get();
assertHitCount(searchResponse, 2L);
assertSearchHits(searchResponse, "1", "3");
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchResponse in project elasticsearch by elastic.
the class SearchQueryIT method testMustNot.
// see #2926
public void testMustNot() throws IOException, ExecutionException, InterruptedException {
assertAcked(prepareCreate("test").setSettings(SETTING_NUMBER_OF_SHARDS, between(2, DEFAULT_MAX_NUM_SHARDS)));
indexRandom(true, client().prepareIndex("test", "test", "1").setSource("description", "foo other anything bar"), client().prepareIndex("test", "test", "2").setSource("description", "foo other anything"), client().prepareIndex("test", "test", "3").setSource("description", "foo other"), client().prepareIndex("test", "test", "4").setSource("description", "foo"));
SearchResponse searchResponse = client().prepareSearch("test").setQuery(matchAllQuery()).setSearchType(SearchType.DFS_QUERY_THEN_FETCH).get();
assertHitCount(searchResponse, 4L);
searchResponse = client().prepareSearch("test").setQuery(boolQuery().mustNot(matchQuery("description", "anything").type(Type.BOOLEAN))).setSearchType(SearchType.DFS_QUERY_THEN_FETCH).get();
assertHitCount(searchResponse, 2L);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchResponse in project elasticsearch by elastic.
the class SearchQueryIT method testMultiMatchQueryMinShouldMatch.
public void testMultiMatchQueryMinShouldMatch() {
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();
MultiMatchQueryBuilder multiMatchQuery = multiMatchQuery("value1 value2 foo", "field1", "field2");
multiMatchQuery.useDisMax(true);
multiMatchQuery.minimumShouldMatch("70%");
SearchResponse searchResponse = client().prepareSearch().setQuery(multiMatchQuery).get();
assertHitCount(searchResponse, 1L);
assertFirstHit(searchResponse, hasId("1"));
multiMatchQuery.minimumShouldMatch("30%");
searchResponse = client().prepareSearch().setQuery(multiMatchQuery).get();
assertHitCount(searchResponse, 2L);
assertFirstHit(searchResponse, hasId("1"));
assertSecondHit(searchResponse, hasId("2"));
multiMatchQuery.useDisMax(false);
multiMatchQuery.minimumShouldMatch("70%");
searchResponse = client().prepareSearch().setQuery(multiMatchQuery).get();
assertHitCount(searchResponse, 1L);
assertFirstHit(searchResponse, hasId("1"));
multiMatchQuery.minimumShouldMatch("30%");
searchResponse = client().prepareSearch().setQuery(multiMatchQuery).get();
assertHitCount(searchResponse, 2L);
assertFirstHit(searchResponse, hasId("1"));
assertSecondHit(searchResponse, hasId("2"));
multiMatchQuery = multiMatchQuery("value1 value2 bar", "field1");
multiMatchQuery.minimumShouldMatch("100%");
searchResponse = client().prepareSearch().setQuery(multiMatchQuery).get();
assertHitCount(searchResponse, 0L);
multiMatchQuery.minimumShouldMatch("70%");
searchResponse = client().prepareSearch().setQuery(multiMatchQuery).get();
assertHitCount(searchResponse, 1L);
assertFirstHit(searchResponse, hasId("1"));
// Min should match > # optional clauses returns no docs.
multiMatchQuery = multiMatchQuery("value1 value2 value3", "field1", "field2");
multiMatchQuery.minimumShouldMatch("4");
searchResponse = client().prepareSearch().setQuery(multiMatchQuery).get();
assertHitCount(searchResponse, 0L);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchResponse in project elasticsearch by elastic.
the class SearchQueryIT method testQueryStringAnalyzedWildcard.
public void testQueryStringAnalyzedWildcard() throws Exception {
createIndex("test");
client().prepareIndex("test", "type1", "1").setSource("field1", "value_1", "field2", "value_2").get();
refresh();
SearchResponse searchResponse = client().prepareSearch().setQuery(queryStringQuery("value*")).get();
assertHitCount(searchResponse, 1L);
searchResponse = client().prepareSearch().setQuery(queryStringQuery("*ue*")).get();
assertHitCount(searchResponse, 1L);
searchResponse = client().prepareSearch().setQuery(queryStringQuery("*ue_1")).get();
assertHitCount(searchResponse, 1L);
searchResponse = client().prepareSearch().setQuery(queryStringQuery("val*e_1")).get();
assertHitCount(searchResponse, 1L);
searchResponse = client().prepareSearch().setQuery(queryStringQuery("v?l*e?1")).get();
assertHitCount(searchResponse, 1L);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchResponse in project elasticsearch by elastic.
the class SearchQueryIT method testDateRangeInQueryStringWithTimeZone_7880.
// Issue #7880
public void testDateRangeInQueryStringWithTimeZone_7880() {
//the mapping needs to be provided upfront otherwise we are not sure how many failures we get back
//as with dynamic mappings some shards might be lacking behind and parse a different query
assertAcked(prepareCreate("test").addMapping("type", "past", "type=date"));
DateTimeZone timeZone = randomDateTimeZone();
String now = ISODateTimeFormat.dateTime().print(new DateTime(timeZone));
logger.info(" --> Using time_zone [{}], now is [{}]", timeZone.getID(), now);
client().prepareIndex("test", "type", "1").setSource("past", now).get();
refresh();
SearchResponse searchResponse = client().prepareSearch().setQuery(queryStringQuery("past:[now-1m/m TO now+1m/m]").timeZone(timeZone.getID())).get();
assertHitCount(searchResponse, 1L);
}
Aggregations