How to setHighlighterNoMatchSize for a specific field?


(Andrew Wooster) #1

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?


(Nik Everett) #2

Have a look at how the tests do it:

It looks like there is a noMatchSize method on HighlightBuilder.Field.


(Andrew Wooster) #3

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) )

(system) #4