use of org.elasticsearch.search.builder.SearchSourceBuilder in project elasticsearch by elastic.
the class HighlighterSearchIT method testPostingsHighlighterMultiTermQueryMultipleLevels.
public void testPostingsHighlighterMultiTermQueryMultipleLevels() throws Exception {
assertAcked(prepareCreate("test").addMapping("type1", type1PostingsffsetsMapping()));
ensureGreen();
client().prepareIndex("test", "type1").setSource("field1", "The photography word will get highlighted").get();
refresh();
for (String type : UNIFIED_AND_NULL) {
logger.info("--> highlighting and searching on field1");
SearchSourceBuilder source = searchSource().query(boolQuery().should(boolQuery().mustNot(QueryBuilders.existsQuery("field1"))).should(matchQuery("field1", "test")).should(constantScoreQuery(queryStringQuery("field1:photo*")))).highlighter(highlight().field("field1").highlighterType(type));
SearchResponse searchResponse = client().prepareSearch("test").setSource(source).get();
assertHighlight(searchResponse, 0, "field1", 0, 1, equalTo("The <em>photography</em> word will get highlighted"));
}
}
use of org.elasticsearch.search.builder.SearchSourceBuilder in project elasticsearch by elastic.
the class HighlighterSearchIT method testPostingsHighlighterQueryString.
public void testPostingsHighlighterQueryString() throws Exception {
assertAcked(prepareCreate("test").addMapping("type1", type1PostingsffsetsMapping()));
ensureGreen();
client().prepareIndex("test", "type1").setSource("field1", "this is a test", "field2", "The quick brown fox jumps over the lazy dog! Second sentence.").get();
refresh();
for (String type : UNIFIED_AND_NULL) {
logger.info("--> highlighting and searching on field2");
SearchSourceBuilder source = searchSource().query(queryStringQuery("qui*").defaultField("field2")).highlighter(highlight().field("field2").highlighterType(type));
SearchResponse searchResponse = client().prepareSearch("test").setSource(source).get();
assertHighlight(searchResponse, 0, "field2", 0, 1, equalTo("The <em>quick</em> brown fox jumps over the lazy dog!"));
}
}
use of org.elasticsearch.search.builder.SearchSourceBuilder in project elasticsearch by elastic.
the class HighlighterSearchIT method testPostingsHighlighterRegexpQuery.
public void testPostingsHighlighterRegexpQuery() throws Exception {
assertAcked(prepareCreate("test").addMapping("type1", type1PostingsffsetsMapping()));
ensureGreen();
client().prepareIndex("test", "type1").setSource("field1", "this is a test", "field2", "The quick brown fox jumps over the lazy dog! Second sentence.").get();
refresh();
for (String type : UNIFIED_AND_NULL) {
logger.info("--> highlighting and searching on field2");
SearchSourceBuilder source = searchSource().query(regexpQuery("field2", "qu[a-l]+k")).highlighter(highlight().field("field2").highlighterType(type));
SearchResponse searchResponse = client().prepareSearch("test").setSource(source).get();
assertHighlight(searchResponse, 0, "field2", 0, 1, equalTo("The <em>quick</em> brown fox jumps over the lazy dog!"));
}
}
use of org.elasticsearch.search.builder.SearchSourceBuilder in project elasticsearch by elastic.
the class HighlighterSearchIT method testPostingsHighlighterCommonTermsQuery.
public void testPostingsHighlighterCommonTermsQuery() throws IOException {
assertAcked(prepareCreate("test").addMapping("type1", type1PostingsffsetsMapping()));
ensureGreen();
client().prepareIndex("test", "type1").setSource("field1", "this is a test", "field2", "The quick brown fox jumps over the lazy dog! Second sentence.").get();
refresh();
for (String type : UNIFIED_AND_NULL) {
logger.info("--> highlighting and searching on field1");
SearchSourceBuilder source = searchSource().query(commonTermsQuery("field2", "quick brown").cutoffFrequency(100)).highlighter(highlight().field("field2").preTags("<x>").postTags("</x>").highlighterType(type));
SearchResponse searchResponse = client().search(searchRequest("test").source(source)).actionGet();
assertHitCount(searchResponse, 1L);
assertHighlight(searchResponse, 0, "field2", 0, 1, equalTo("The <x>quick</x> <x>brown</x> fox jumps over the lazy dog!"));
}
}
use of org.elasticsearch.search.builder.SearchSourceBuilder in project elasticsearch by elastic.
the class HighlighterSearchIT method testPostingsHighlighterPrefixQueryWithinBooleanQuery.
public void testPostingsHighlighterPrefixQueryWithinBooleanQuery() throws Exception {
assertAcked(prepareCreate("test").addMapping("type1", type1PostingsffsetsMapping()));
ensureGreen();
client().prepareIndex("test", "type1").setSource("field1", "The photography word will get highlighted").get();
refresh();
for (String type : UNIFIED_AND_NULL) {
logger.info("--> highlighting and searching on field1");
SearchSourceBuilder source = searchSource().query(boolQuery().must(prefixQuery("field1", "photo")).should(matchQuery("field1", "test").minimumShouldMatch("0"))).highlighter(highlight().field("field1").highlighterType(type));
SearchResponse searchResponse = client().prepareSearch("test").setSource(source).get();
assertHighlight(searchResponse, 0, "field1", 0, 1, equalTo("The <em>photography</em> word will get highlighted"));
}
}
Aggregations