# Highlighting issue with proximity phrase match

**URL:** <https://discuss.elastic.co/t/highlighting-issue-with-proximity-phrase-match/18955>\
**Category:** Elasticsearch\
**Created:** [July 29, 2014, 5:43pm UTC](https://discuss.elastic.co/t/highlighting-issue-with-proximity-phrase-match/18955 "2014-07-29T17:43:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joyce\_Wu](https://avatars.discourse-cdn.com/v4/letter/j/e8c25b/32.png) [@Joyce\_Wu](https://discuss.elastic.co/u/Joyce_Wu)\
**Post date:** [July 29, 2014, 5:43pm UTC](https://discuss.elastic.co/t/highlighting-issue-with-proximity-phrase-match/18955/1 "2014-07-29T17:43:37Z")

</div>

Hi

I need to support searches like " green apple" near "yellow peach", but  
can't find existing query syntax from ElaticSearch to support this directly.  
So I tried to combine multiple phrase match with a boolean query to  
achieve this. It doesn't work perfectly, but search results are close  
enough. However, I can't find a good way to highlight the match terms  
correctly as my client only wants to highlight the phrase "green apple" and  
"yellow peach" where they near each other. With the query I come up, all  
the individual word could be highlighted as well if I have a sentence like  
"green and red apple with yellow banana and pink peach", assuming somewhere  
in the text would have two phrases "green apple" and "yellow peach" that  
satisfy the query.

I use standard tokenizer with snowball filter for the text field, and term\_vector  
with\_postions\_offsets is used for highlighting.

Here is my query:

"query":

{"bool":{"must":

```
          [{"match_phrase":{"headline":{"text":"green apple"}}},

           {"match_phrase":{"headline":{"text":"yellow peach"}}},

           {"match_phrase":{"headline":{"text":"green apple yellow 

```

peach","slop":10}}}

```
          ]

}}

```

"highlight":

{"fields":{"text":{}},

```
"fragment_size":200,

"number_of_fragments":50,

"highlight_query":{""match_phrase":{"headline":{"text":"green apple 

```

yellow peach","slop":10}}},

```
"require_field_match":true

}

```

I tried span near query, but I can't find span term that support phrases,  
and I believe span query only works on not-analyzed fields.

Can anyone have suggestions to handle the highlighting for such proximity  
phrase searches? Thanks.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/18cdb5cb-3aed-4d87-95ec-2d146306117b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/18cdb5cb-3aed-4d87-95ec-2d146306117b%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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 6, 2017, 1:12am UTC](https://discuss.elastic.co/t/highlighting-issue-with-proximity-phrase-match/18955/2 "2017-07-06T01:12:28Z")

</div>


