use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.SearchHit in project elasticsearch by elastic.
the class MatchedQueriesIT method testRegExpQuerySupportsName.
public void testRegExpQuerySupportsName() {
createIndex("test1");
ensureGreen();
client().prepareIndex("test1", "type1", "1").setSource("title", "title1").get();
refresh();
SearchResponse searchResponse = client().prepareSearch().setQuery(QueryBuilders.regexpQuery("title", "title1").queryName("regex")).get();
assertHitCount(searchResponse, 1L);
for (SearchHit hit : searchResponse.getHits()) {
if (hit.getId().equals("1")) {
assertThat(hit.getMatchedQueries().length, equalTo(1));
assertThat(hit.getMatchedQueries(), hasItemInArray("regex"));
} else {
fail("Unexpected document returned with id " + hit.getId());
}
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.SearchHit in project elasticsearch by elastic.
the class MatchedQueriesIT method testPrefixQuerySupportsName.
public void testPrefixQuerySupportsName() {
createIndex("test1");
ensureGreen();
client().prepareIndex("test1", "type1", "1").setSource("title", "title1").get();
refresh();
SearchResponse searchResponse = client().prepareSearch().setQuery(QueryBuilders.prefixQuery("title", "title").queryName("prefix")).get();
assertHitCount(searchResponse, 1L);
for (SearchHit hit : searchResponse.getHits()) {
if (hit.getId().equals("1")) {
assertThat(hit.getMatchedQueries().length, equalTo(1));
assertThat(hit.getMatchedQueries(), hasItemInArray("prefix"));
} else {
fail("Unexpected document returned with id " + hit.getId());
}
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.SearchHit in project elasticsearch by elastic.
the class MatchedQueriesIT method testMatchedWithShould.
/**
* Test case for issue #4361: https://github.com/elastic/elasticsearch/issues/4361
*/
public void testMatchedWithShould() throws Exception {
createIndex("test");
ensureGreen();
client().prepareIndex("test", "type1", "1").setSource("content", "Lorem ipsum dolor sit amet").get();
client().prepareIndex("test", "type1", "2").setSource("content", "consectetur adipisicing elit").get();
refresh();
// Execute search at least two times to load it in cache
int iter = scaledRandomIntBetween(2, 10);
for (int i = 0; i < iter; i++) {
SearchResponse searchResponse = client().prepareSearch().setQuery(boolQuery().minimumShouldMatch(1).should(queryStringQuery("dolor").queryName("dolor")).should(queryStringQuery("elit").queryName("elit"))).setPreference("_primary").get();
assertHitCount(searchResponse, 2L);
for (SearchHit hit : searchResponse.getHits()) {
if (hit.getId().equals("1")) {
assertThat(hit.getMatchedQueries().length, equalTo(1));
assertThat(hit.getMatchedQueries(), hasItemInArray("dolor"));
} else if (hit.getId().equals("2")) {
assertThat(hit.getMatchedQueries().length, equalTo(1));
assertThat(hit.getMatchedQueries(), hasItemInArray("elit"));
} else {
fail("Unexpected document returned with id " + hit.getId());
}
}
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.SearchHit in project elasticsearch by elastic.
the class MatchedQueriesIT method testSimpleMatchedQueryFromTopLevelFilter.
public void testSimpleMatchedQueryFromTopLevelFilter() throws Exception {
createIndex("test");
ensureGreen();
client().prepareIndex("test", "type1", "1").setSource("name", "test", "title", "title1").get();
client().prepareIndex("test", "type1", "2").setSource("name", "test").get();
client().prepareIndex("test", "type1", "3").setSource("name", "test").get();
refresh();
SearchResponse searchResponse = client().prepareSearch().setQuery(matchAllQuery()).setPostFilter(boolQuery().should(termQuery("name", "test").queryName("name")).should(termQuery("title", "title1").queryName("title"))).get();
assertHitCount(searchResponse, 3L);
for (SearchHit hit : searchResponse.getHits()) {
if (hit.getId().equals("1")) {
assertThat(hit.getMatchedQueries().length, equalTo(2));
assertThat(hit.getMatchedQueries(), hasItemInArray("name"));
assertThat(hit.getMatchedQueries(), hasItemInArray("title"));
} else if (hit.getId().equals("2") || hit.getId().equals("3")) {
assertThat(hit.getMatchedQueries().length, equalTo(1));
assertThat(hit.getMatchedQueries(), hasItemInArray("name"));
} else {
fail("Unexpected document returned with id " + hit.getId());
}
}
searchResponse = client().prepareSearch().setQuery(matchAllQuery()).setPostFilter(boolQuery().should(termQuery("name", "test").queryName("name")).should(termQuery("title", "title1").queryName("title"))).get();
assertHitCount(searchResponse, 3L);
for (SearchHit hit : searchResponse.getHits()) {
if (hit.getId().equals("1")) {
assertThat(hit.getMatchedQueries().length, equalTo(2));
assertThat(hit.getMatchedQueries(), hasItemInArray("name"));
assertThat(hit.getMatchedQueries(), hasItemInArray("title"));
} else if (hit.getId().equals("2") || hit.getId().equals("3")) {
assertThat(hit.getMatchedQueries().length, equalTo(1));
assertThat(hit.getMatchedQueries(), hasItemInArray("name"));
} else {
fail("Unexpected document returned with id " + hit.getId());
}
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.SearchHit in project elasticsearch by elastic.
the class MatchedQueriesIT method testWildcardQuerySupportsName.
public void testWildcardQuerySupportsName() {
createIndex("test1");
ensureGreen();
client().prepareIndex("test1", "type1", "1").setSource("title", "title1").get();
refresh();
SearchResponse searchResponse = client().prepareSearch().setQuery(QueryBuilders.wildcardQuery("title", "titl*").queryName("wildcard")).get();
assertHitCount(searchResponse, 1L);
for (SearchHit hit : searchResponse.getHits()) {
if (hit.getId().equals("1")) {
assertThat(hit.getMatchedQueries().length, equalTo(1));
assertThat(hit.getMatchedQueries(), hasItemInArray("wildcard"));
} else {
fail("Unexpected document returned with id " + hit.getId());
}
}
}
Aggregations