# How to setHighlighterNoMatchSize for a specific field?

**URL:** https://discuss.elastic.co/t/how-to-sethighlighternomatchsize-for-a-specific-field/34212
**Category:** Elasticsearch
**Created:** [November 10, 2015, 2:14am UTC](https://discuss.elastic.co/t/how-to-sethighlighternomatchsize-for-a-specific-field/34212 "2015-11-10T02:14:48Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![andrewwwooster](https://avatars.discourse-cdn.com/v4/letter/a/da6949/32.png) [@andrewwwooster](https://discuss.elastic.co/u/andrewwwooster)
#### Post date: [November 10, 2015, 2:14am UTC](https://discuss.elastic.co/t/how-to-sethighlighternomatchsize-for-a-specific-field/34212/1 "2015-11-10T02:14:48Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)
#### Post date: [November 11, 2015, 1:21pm UTC](https://discuss.elastic.co/t/how-to-sethighlighternomatchsize-for-a-specific-field/34212/2 "2015-11-11T13:21:50Z")

</div>

Have a look at how the tests do it:

> <https://github.com/elastic/elasticsearch/blob/93b57089d0c02b4ab5a589bc481ab5ccf3eb8c2b/core/src/test/java/org/elasticsearch/search/highlight/HighlighterSearchIT.java#L1772>

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

---

<div class="post-metadata">

### Author: ![andrewwwooster](https://avatars.discourse-cdn.com/v4/letter/a/da6949/32.png) [@andrewwwooster](https://discuss.elastic.co/u/andrewwwooster)
#### Post date: [November 11, 2015, 3:36pm UTC](https://discuss.elastic.co/t/how-to-sethighlighternomatchsize-for-a-specific-field/34212/3 "2015-11-11T15:36:21Z")

</div>

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

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [July 5, 2017, 11:39pm UTC](https://discuss.elastic.co/t/how-to-sethighlighternomatchsize-for-a-specific-field/34212/4 "2017-07-05T23:39:10Z")

</div>


