# Highlighting for multiple phrases?

**URL:** <https://discuss.elastic.co/t/highlighting-for-multiple-phrases/8368>\
**Category:** Elasticsearch\
**Created:** [July 10, 2012, 2:05am UTC](https://discuss.elastic.co/t/highlighting-for-multiple-phrases/8368 "2012-07-10T02:05:31Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![benallfree](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/benallfree/32/2821_2.png) [@benallfree](https://discuss.elastic.co/u/benallfree)\
**Post date:** [July 10, 2012, 2:05am UTC](https://discuss.elastic.co/t/highlighting-for-multiple-phrases/8368/1 "2012-07-10T02:05:31Z")

</div>

Hi everyone,

I'm having trouble forming the syntax to search for multiple phrases with  
highlighting. Suppose I would like to search for:

(red balloon) OR (yellow kite) OR (black sheep)

...and highlight the results. What would the JSON look like?

For reference, I can do this using an OR filter and text\_phrase, but I  
don't know how to do an OR inside a query. It seems that highlighting only  
works if the terms are specified in the query (not the filter).

Thanks for any help you can lend.

Ben

---

<div class="post-metadata">

**Author:** ![Shaun\_Etherton](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shaun_etherton/32/2540_2.png) [@Shaun\_Etherton](https://discuss.elastic.co/u/Shaun_Etherton)\
**Post date:** [July 10, 2012, 2:33am UTC](https://discuss.elastic.co/t/highlighting-for-multiple-phrases/8368/2 "2012-07-10T02:33:06Z")

</div>

Hi Ben

Maybe these will help?

[https://gist.github.com/3053914](https://gist.github.com/3053914)

[https://gist.github.com/3080627](https://gist.github.com/3080627)

cheers

On Tuesday, 10 July 2012 at 11:35 AM, Ben Allfree wrote:

> Hi everyone,
> 
> I'm having trouble forming the syntax to search for multiple phrases with highlighting. Suppose I would like to search for:
> 
> (red balloon) OR (yellow kite) OR (black sheep)
> 
> ...and highlight the results. What would the JSON look like?
> 
> For reference, I can do this using an OR filter and text\_phrase, but I don't know how to do an OR inside a query. It seems that highlighting only works if the terms are specified in the query (not the filter).
> 
> Thanks for any help you can lend.
> 
> Ben

---

<div class="post-metadata">

**Author:** ![benallfree](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/benallfree/32/2821_2.png) [@benallfree](https://discuss.elastic.co/u/benallfree)\
**Post date:** [July 10, 2012, 2:40am UTC](https://discuss.elastic.co/t/highlighting-for-multiple-phrases/8368/3 "2012-07-10T02:40:26Z")

</div>

Thanks, I hadn't seen those. Unfortunately I don't think query\_string can  
do nesting for phrases.

dog OR cat OR bird

will work, but

black dog OR brown cat OR red bird

will not ☹

b

On Mon, Jul 9, 2012 at 7:33 PM, shaun etherton [shaun.etherton@gmail.com](mailto:shaun.etherton@gmail.com)wrote:

> Hi Ben
> 
> Maybe these will help?
> 
> [https://gist.github.com/3053914](https://gist.github.com/3053914)
> 
> [https://gist.github.com/3080627](https://gist.github.com/3080627)
> 
> cheers
> 
> On Tuesday, 10 July 2012 at 11:35 AM, Ben Allfree wrote:
> 
> Hi everyone,
> 
> I'm having trouble forming the syntax to search for multiple phrases with  
> highlighting. Suppose I would like to search for:
> 
> (red balloon) OR (yellow kite) OR (black sheep)
> 
> ...and highlight the results. What would the JSON look like?
> 
> For reference, I can do this using an OR filter and text\_phrase, but I  
> don't know how to do an OR inside a query. It seems that highlighting only  
> works if the terms are specified in the query (not the filter).
> 
> Thanks for any help you can lend.
> 
> Ben

---

<div class="post-metadata">

**Author:** ![Shaun\_Etherton](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shaun_etherton/32/2540_2.png) [@Shaun\_Etherton](https://discuss.elastic.co/u/Shaun_Etherton)\
**Post date:** [July 10, 2012, 2:45am UTC](https://discuss.elastic.co/t/highlighting-for-multiple-phrases/8368/4 "2012-07-10T02:45:01Z")

</div>

Oh, i see. I didn't realise they were nested phrases.

When you workout how to do it can you gist a small example query so i can add it to my list of reference queries?

cheers.

--  
shaun etherton  
Sent with Sparrow ([http://www.sparrowmailapp.com/?sig](http://www.sparrowmailapp.com/?sig))

On Tuesday, 10 July 2012 at 12:10 PM, Ben Allfree wrote:

> Thanks, I hadn't seen those. Unfortunately I don't think query\_string can do nesting for phrases.
> 
> dog OR cat OR bird
> 
> will work, but
> 
> black dog OR brown cat OR red bird
> 
> will not ☹
> 
> b
> 
> On Mon, Jul 9, 2012 at 7:33 PM, shaun etherton \<[shaun.etherton@gmail.com](mailto:shaun.etherton@gmail.com) ([mailto:shaun.etherton@gmail.com](mailto:shaun.etherton@gmail.com))\> wrote:
> 
> > Hi Ben
> > 
> > Maybe these will help?
> > 
> > [https://gist.github.com/3053914](https://gist.github.com/3053914)
> > 
> > [https://gist.github.com/3080627](https://gist.github.com/3080627)
> > 
> > cheers
> > 
> > On Tuesday, 10 July 2012 at 11:35 AM, Ben Allfree wrote:
> > 
> > > Hi everyone,
> > > 
> > > I'm having trouble forming the syntax to search for multiple phrases with highlighting. Suppose I would like to search for:
> > > 
> > > (red balloon) OR (yellow kite) OR (black sheep)
> > > 
> > > ...and highlight the results. What would the JSON look like?
> > > 
> > > For reference, I can do this using an OR filter and text\_phrase, but I don't know how to do an OR inside a query. It seems that highlighting only works if the terms are specified in the query (not the filter).
> > > 
> > > Thanks for any help you can lend.
> > > 
> > > Ben

---

<div class="post-metadata">

**Author:** ![benallfree](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/benallfree/32/2821_2.png) [@benallfree](https://discuss.elastic.co/u/benallfree)\
**Post date:** [July 10, 2012, 2:48am UTC](https://discuss.elastic.co/t/highlighting-for-multiple-phrases/8368/5 "2012-07-10T02:48:36Z")

</div>

Sure. It would work perfectly if you could go:

text\_phrase: ["black dog", "brown cat", "red bird"]

But text\_phrase doesn't support arrays. You can do:

terms: ["black dog", "brown cat", "red bird"]

But terms doesn't support multiple words in a term so you get 0 results  
back.

b

On Mon, Jul 9, 2012 at 7:45 PM, shaun etherton [shaun.etherton@gmail.com](mailto:shaun.etherton@gmail.com)wrote:

> Oh, i see. I didn't realise they were nested phrases.
> 
> When you workout how to do it can you gist a small example query so i can  
> add it to my list of reference queries?
> 
> cheers.
> 
> --  
> shaun etherton  
> Sent with Sparrow [http://www.sparrowmailapp.com/?sig](http://www.sparrowmailapp.com/?sig)
> 
> On Tuesday, 10 July 2012 at 12:10 PM, Ben Allfree wrote:
> 
> Thanks, I hadn't seen those. Unfortunately I don't think query\_string can  
> do nesting for phrases.
> 
> dog OR cat OR bird
> 
> will work, but
> 
> black dog OR brown cat OR red bird
> 
> will not ☹
> 
> b
> 
> On Mon, Jul 9, 2012 at 7:33 PM, shaun etherton [shaun.etherton@gmail.com](mailto:shaun.etherton@gmail.com)wrote:
> 
> Hi Ben
> 
> Maybe these will help?
> 
> [https://gist.github.com/3053914](https://gist.github.com/3053914)
> 
> [https://gist.github.com/3080627](https://gist.github.com/3080627)
> 
> cheers
> 
> On Tuesday, 10 July 2012 at 11:35 AM, Ben Allfree wrote:
> 
> Hi everyone,
> 
> I'm having trouble forming the syntax to search for multiple phrases with  
> highlighting. Suppose I would like to search for:
> 
> (red balloon) OR (yellow kite) OR (black sheep)
> 
> ...and highlight the results. What would the JSON look like?
> 
> For reference, I can do this using an OR filter and text\_phrase, but I  
> don't know how to do an OR inside a query. It seems that highlighting only  
> works if the terms are specified in the query (not the filter).
> 
> Thanks for any help you can lend.
> 
> Ben

---

<div class="post-metadata">

**Author:** ![Lukas\_Vlcek1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukas_vlcek1/32/819_2.png) [@Lukas\_Vlcek1](https://discuss.elastic.co/u/Lukas_Vlcek1)\
**Post date:** [July 10, 2012, 4:32am UTC](https://discuss.elastic.co/t/highlighting-for-multiple-phrases/8368/6 "2012-07-10T04:32:29Z")

</div>

Hi,

"black dog" OR "brown cat" OR "red bird"

^^ does this work for you?

Regards,  
Lukas

On Tue, Jul 10, 2012 at 4:48 AM, Ben Allfree [ben@benallfree.com](mailto:ben@benallfree.com) wrote:

> Sure. It would work perfectly if you could go:
> 
> text\_phrase: ["black dog", "brown cat", "red bird"]
> 
> But text\_phrase doesn't support arrays. You can do:
> 
> terms: ["black dog", "brown cat", "red bird"]
> 
> But terms doesn't support multiple words in a term so you get 0 results  
> back.
> 
> b
> 
> On Mon, Jul 9, 2012 at 7:45 PM, shaun etherton [shaun.etherton@gmail.com](mailto:shaun.etherton@gmail.com)wrote:
> 
> > Oh, i see. I didn't realise they were nested phrases.
> > 
> > When you workout how to do it can you gist a small example query so i can  
> > add it to my list of reference queries?
> > 
> > cheers.
> > 
> > --  
> > shaun etherton  
> > Sent with Sparrow [http://www.sparrowmailapp.com/?sig](http://www.sparrowmailapp.com/?sig)
> > 
> > On Tuesday, 10 July 2012 at 12:10 PM, Ben Allfree wrote:
> > 
> > Thanks, I hadn't seen those. Unfortunately I don't think query\_string can  
> > do nesting for phrases.
> > 
> > dog OR cat OR bird
> > 
> > will work, but
> > 
> > black dog OR brown cat OR red bird
> > 
> > will not ☹
> > 
> > b
> > 
> > On Mon, Jul 9, 2012 at 7:33 PM, shaun etherton [shaun.etherton@gmail.com](mailto:shaun.etherton@gmail.com)wrote:
> > 
> > Hi Ben
> > 
> > Maybe these will help?
> > 
> > [https://gist.github.com/3053914](https://gist.github.com/3053914)
> > 
> > [https://gist.github.com/3080627](https://gist.github.com/3080627)
> > 
> > cheers
> > 
> > On Tuesday, 10 July 2012 at 11:35 AM, Ben Allfree wrote:
> > 
> > Hi everyone,
> > 
> > I'm having trouble forming the syntax to search for multiple phrases with  
> > highlighting. Suppose I would like to search for:
> > 
> > (red balloon) OR (yellow kite) OR (black sheep)
> > 
> > ...and highlight the results. What would the JSON look like?
> > 
> > For reference, I can do this using an OR filter and text\_phrase, but I  
> > don't know how to do an OR inside a query. It seems that highlighting only  
> > works if the terms are specified in the query (not the filter).
> > 
> > Thanks for any help you can lend.
> > 
> > Ben

---

<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, 3:20am UTC](https://discuss.elastic.co/t/highlighting-for-multiple-phrases/8368/7 "2017-07-06T03:20:50Z")

</div>


