Using JSON I can specify no_match_size for a highlight field.
"highlight": {
"fields" : {
"f1" : {"no_match_size": 100},
"f2" : {"no_match_size": 200}
}
}
However, using the Java API it looks like setHighlighterNoMatchSize() applies to all highlighted fields in the search request. Is there a way to using Java to specify different highlight no_match_sizes for different fields?
nik9000
(Nik Everett)
November 11, 2015, 1:21pm
2
Have a look at how the tests do it:
field.highlighterType("fvh");
response = client().prepareSearch("test").highlighter(new HighlightBuilder().field(field)).get();
assertNotHighlighted(response, 0, "text");
field.highlighterType("postings");
response = client().prepareSearch("test").highlighter(new HighlightBuilder().field(field)).get();
assertNotHighlighted(response, 0, "text");
// When noMatchSize is set to 0 you also shouldn't get any
field.highlighterType("plain").noMatchSize(0);
response = client().prepareSearch("test").highlighter(new HighlightBuilder().field(field)).get();
assertNotHighlighted(response, 0, "text");
field.highlighterType("fvh");
response = client().prepareSearch("test").highlighter(new HighlightBuilder().field(field)).get();
assertNotHighlighted(response, 0, "text");
field.highlighterType("postings");
response = client().prepareSearch("test").highlighter(new HighlightBuilder().field(field)).get();
assertNotHighlighted(response, 0, "text");
It looks like there is a noMatchSize
method on HighlightBuilder.Field
.
Thanks for the insight. My solution now looks like this:
SearchResponse response = client.prepareSearch("my_index")
.addHighlightedField(
new HighlightBuilder.Field("preferredSnippet")
.fragmentSize(10000)
.noMatchSize(10000) )