# Highlighting feature issue in case of complex query

**URL:** <https://discuss.elastic.co/t/highlighting-feature-issue-in-case-of-complex-query/8974>\
**Category:** Elasticsearch\
**Created:** [September 10, 2012, 2:13pm UTC](https://discuss.elastic.co/t/highlighting-feature-issue-in-case-of-complex-query/8974 "2012-09-10T14:13:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Robert\_Moszczynski](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/robert_moszczynski/32/2727_2.png) [@Robert\_Moszczynski](https://discuss.elastic.co/u/Robert_Moszczynski)\
**Post date:** [September 10, 2012, 2:13pm UTC](https://discuss.elastic.co/t/highlighting-feature-issue-in-case-of-complex-query/8974/1 "2012-09-10T14:13:04Z")

</div>

Hi, I have a problem with the highlighting feature. In my query I use  
dis\_max, constant\_score, bool and query\_string together. It works when I  
use for example only the terms query or only the query string query. Are  
there any restrictions on the use of highlighting?

ES versions: 0.18.1, 0.19.9

{  
"sort": [  
{  
"\_score": "desc"  
},  
{  
"name": "asc"  
}  
],  
"from": 0,  
"size": 50,  
"highlight": {  
"fragment\_size": 0,  
"number\_of\_fragments": 0,  
"fields": {  
"names": {},  
"content": {}  
}  
},  
"query": {  
"dis\_max": {  
"tie\_breaker": 0.0,  
"queries": [  
{  
"constant\_score": {  
"query": {  
"bool": {  
"should": [  
{  
"bool": {  
"must": [  
{  
"query\_string": {  
"query": "foo AND NOT bar",  
"fields": [  
"names",  
"content"  
]  
}  
},  
...  
]  
}  
}  
]  
}  
},  
"boost": 20.0  
}  
},  
...  
]  
}  
}  
}

--

---

<div class="post-metadata">

**Author:** ![Robert\_Moszczynski](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/robert_moszczynski/32/2727_2.png) [@Robert\_Moszczynski](https://discuss.elastic.co/u/Robert_Moszczynski)\
**Post date:** [September 11, 2012, 8:49am UTC](https://discuss.elastic.co/t/highlighting-feature-issue-in-case-of-complex-query/8974/2 "2012-09-11T08:49:16Z")

</div>

Problem solved. I declare the following in the mapping for the fields I  
want to highlight:

:term\_vector =\> "with\_positions\_offsets", :store =\> "yes"

This enables the fast vector highlighter.

On Monday, September 10, 2012 4:13:04 PM UTC+2, Robert Moszczynski wrote:

> Hi, I have a problem with the highlighting feature. In my query I use  
> dis\_max, constant\_score, bool and query\_string together. It works when I  
> use for example only the terms query or only the query string query. Are  
> there any restrictions on the use of highlighting?
> 
> ES versions: 0.18.1, 0.19.9
> 
> {  
> "sort": [  
> {  
> "\_score": "desc"  
> },  
> {  
> "name": "asc"  
> }  
> ],  
> "from": 0,  
> "size": 50,  
> "highlight": {  
> "fragment\_size": 0,  
> "number\_of\_fragments": 0,  
> "fields": {  
> "names": {},  
> "content": {}  
> }  
> },  
> "query": {  
> "dis\_max": {  
> "tie\_breaker": 0.0,  
> "queries": [  
> {  
> "constant\_score": {  
> "query": {  
> "bool": {  
> "should": [  
> {  
> "bool": {  
> "must": [  
> {  
> "query\_string": {  
> "query": "foo AND NOT bar",  
> "fields": [  
> "names",  
> "content"  
> ]  
> }  
> },  
> ...  
> ]  
> }  
> }  
> ]  
> }  
> },  
> "boost": 20.0  
> }  
> },  
> ...  
> ]  
> }  
> }  
> }

--

---

<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:13am UTC](https://discuss.elastic.co/t/highlighting-feature-issue-in-case-of-complex-query/8974/3 "2017-07-06T03:13:15Z")

</div>


