# Highlight works incorrectly

**URL:** <https://discuss.elastic.co/t/highlight-works-incorrectly/7069>\
**Category:** Elasticsearch\
**Created:** [March 20, 2012, 11:23am UTC](https://discuss.elastic.co/t/highlight-works-incorrectly/7069 "2012-03-20T11:23:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anhthu](https://avatars.discourse-cdn.com/v4/letter/a/8e8cbc/32.png) [@anhthu](https://discuss.elastic.co/u/anhthu)\
**Post date:** [March 20, 2012, 11:23am UTC](https://discuss.elastic.co/t/highlight-works-incorrectly/7069/1 "2012-03-20T11:23:35Z")

</div>

hi,

I'm now using ELS v.0.20.0. I have problem with highlighting.

My mapping:  
curl -XPUT "http://:9200$ip/business?pretty=1" -d '  
{  
"mappings": {  
"product": {  
"properties": {  
"productKey": {  
"type": "long"  
},  
"denotation": {  
"fields": {  
"denotation": {  
"type": "string",  
"analyzer": "full\_denotation"  
},  
"untouched" : {"type" : "string", "index" :  
"not\_analyzed"}  
},  
"type": "multi\_field"  
},  
"alias": {  
"properties" : {  
"value" : {  
"fields": {  
"value": {  
"type": "string",  
"analyzer": "full\_denotation"  
},  
"untouched" : {"type" : "string", "index" :  
"not\_analyzed"}  
},  
"type": "multi\_field"  
}  
},  
"type" : "nested"  
}  
}  
}  
},  
"settings": {  
"analysis": {  
"filter": {  
"denotation\_snow": {  
"type": "snowball",  
"language": "German2"  
}  
},  
"analyzer": {  
"full\_denotation": {  
"filter": [  
"standard",  
"lowercase",  
"icu\_folding",  
"denotation\_snow"  
],  
"type": "custom",  
"tokenizer": "standard"  
}  
}  
}  
}  
}'

* * *

My data:  
curl -XPUT 'http://$my\_ip:9200/business/product/1' -d '{  
"productKey":1,  
"denotation":"Schienenpersonenfernverkehr (SPFV)",  
"alias":[  
{"value":"Kombiverkehr, Strasse-Schiene"},  
{"value":"Kombiverkehr Strasse-Schiene, Containertransporte"},  
{"value":"Kombiverkehr Strasse-Schiene, Betontransporte"},  
{"value":"Kombiverkehr Strasse-Schiene,  
Festbrennstofftransporte"}]  
}'

* * *

## My query: { "query": { "bool": { "should": [{ "query\_string": { "query": "_strass_ _schien_", "fields": [ "denotation"], "use\_dis\_max": true, "default\_operator": "and", "allow\_leading\_wildcard": true } }, { "nested": { "query": { "query\_string": { "query": "_strass_ _schien_", "fields": ["alias.value"], "use\_dis\_max": true, "default\_operator": "and", "allow\_leading\_wildcard": true } }, "path": "alias" } } ], "minimum\_number\_should\_match": 1 } }, "highlight": { "require\_field\_match": true, "fields": { "denotation": {} } } }

Although all operators are AND, the highlight seems to be incorrect:  
Here is search result:  
{

```
took: 2
timed_out: false
_shards: {
    total: 5
    successful: 5
    failed: 0
}
hits: {
    total: 1
    max_score: 0.57735026
    hits: [
        {
            _index: business
            _type: product
            _id: 1
            _score: 0.57735026
            _source: {
                productKey: 1
                denotation: Schienenpersonenfernverkehr (SPFV)
                alias: [
                    {
                        value: Kombiverkehr, Strasse-Schiene
                    }
                    {
                        value: Kombiverkehr Strasse-Schiene,

```

Containertransporte  
}  
{  
value: Kombiverkehr Strasse-Schiene,  
Betontransporte  
}  
{  
value: Kombiverkehr Strasse-Schiene,  
Festbrennstofftransporte  
}  
]  
}  
highlight: {  
denotation: [  
_Schienenpersonenfernverkehr_ (SPFV)  
]  
}  
}  
]  
}  
}  
I wonder why the denotation ""Schienenpersonenfernverkehr" is  
highlighted when it just matched with 1 token (_schien_). If i  
separate my query into 2 queries, one for nested object only and one  
for query on denotation, both work fine.

The result I expected is:  
{  
took: 2  
timed\_out: false  
\_shards: {  
total: 5  
successful: 5  
failed: 0  
}  
hits: {  
total: 1  
max\_score: 0.57735026  
hits: [  
{  
\_index: business  
\_type: product  
\_id: 1  
\_score: 0.57735026  
\_source: {  
productKey: 1  
denotation: Schienenpersonenfernverkehr (SPFV)  
alias: [  
{  
value: Kombiverkehr, Strasse-Schiene  
}  
{  
value: Kombiverkehr Strasse-Schiene,  
Containertransporte  
}  
{  
value: Kombiverkehr Strasse-Schiene,  
Betontransporte  
}  
{  
value: Kombiverkehr Strasse-Schiene,  
Festbrennstofftransporte  
}  
]  
}  
}  
]  
}  
}

If anyone could help me on this, it's really appriciated, thanks so  
much.

anhthu

---

<div class="post-metadata">

**Author:** ![anhthu](https://avatars.discourse-cdn.com/v4/letter/a/8e8cbc/32.png) [@anhthu](https://discuss.elastic.co/u/anhthu)\
**Post date:** [March 27, 2012, 8:07am UTC](https://discuss.elastic.co/t/highlight-works-incorrectly/7069/2 "2012-03-27T08:07:24Z")

</div>

hi,

is there any help?

On Mar 20, 6:23 pm, Anh Thu [dinhvuanh...@gmail.com](mailto:dinhvuanh...@gmail.com) wrote:

> hi,
> 
> I'm now using ELS v.0.20.0. I have problem with highlighting.
> 
> My mapping:  
> curl -XPUT "http://:9200$ip/business?pretty=1" -d '  
> {  
> "mappings": {  
> "product": {  
> "properties": {  
> "productKey": {  
> "type": "long"  
> },  
> "denotation": {  
> "fields": {  
> "denotation": {  
> "type": "string",  
> "analyzer": "full\_denotation"  
> },  
> "untouched" : {"type" : "string", "index" :  
> "not\_analyzed"}  
> },  
> "type": "multi\_field"  
> },  
> "alias": {  
> "properties" : {  
> "value" : {  
> "fields": {  
> "value": {  
> "type": "string",  
> "analyzer": "full\_denotation"  
> },  
> "untouched" : {"type" : "string", "index" :  
> "not\_analyzed"}  
> },  
> "type": "multi\_field"  
> }  
> },  
> "type" : "nested"  
> }  
> }  
> }},
> 
> "settings": {  
> "analysis": {  
> "filter": {  
> "denotation\_snow": {  
> "type": "snowball",  
> "language": "German2"  
> }  
> },  
> "analyzer": {  
> "full\_denotation": {  
> "filter": [  
> "standard",  
> "lowercase",  
> "icu\_folding",  
> "denotation\_snow"  
> ],  
> "type": "custom",  
> "tokenizer": "standard"  
> }  
> }  
> }  
> }
> 
> }'
> 
> * * *
> 
> My data:  
> curl -XPUT 'http://$my\_ip:9200/business/product/1' -d '{  
> "productKey":1,  
> "denotation":"Schienenpersonenfernverkehr (SPFV)",  
> "alias":[  
> {"value":"Kombiverkehr, Strasse-Schiene"},  
> {"value":"Kombiverkehr Strasse-Schiene, Containertransporte"},  
> {"value":"Kombiverkehr Strasse-Schiene, Betontransporte"},  
> {"value":"Kombiverkehr Strasse-Schiene,  
> Festbrennstofftransporte"}]
> 
> }'
> 
> * * *
> 
> My query:  
> {  
> "query": {  
> "bool": {  
> "should": [  
> {  
> "query\_string": {  
> "query": "_strass_ _schien_",  
> "fields": [  
> "denotation"  
> ],  
> "use\_dis\_max": true,  
> "default\_operator": "and",  
> "allow\_leading\_wildcard": true  
> }  
> },  
> {  
> "nested": {  
> "query": {  
> "query\_string": {  
> "query": "_strass_ _schien_",  
> "fields": [  
> "alias.value"  
> ],  
> "use\_dis\_max": true,  
> "default\_operator": "and",  
> "allow\_leading\_wildcard": true  
> }  
> },  
> "path": "alias"  
> }  
> }  
> ],  
> "minimum\_number\_should\_match": 1  
> }  
> },  
> "highlight": {  
> "require\_field\_match": true,  
> "fields": {  
> "denotation": {}  
> }  
> }}
> 
> * * *
> 
> Although all operators are AND, the highlight seems to be incorrect:  
> Here is search result:  
> {
> 
> ```
> took: 2
> timed_out: false
> _shards: {
> total: 5
> successful: 5
> failed: 0
> }
> hits: {
> total: 1
> max_score: 0.57735026
> hits: [
> {
> _index: business
> _type: product
> _id: 1
> _score: 0.57735026
> _source: {
> productKey: 1
> denotation: Schienenpersonenfernverkehr (SPFV)
> alias: [
> {
> value: Kombiverkehr, Strasse-Schiene
> }
> {
> value: Kombiverkehr Strasse-Schiene,
> 
> ```
> 
> Containertransporte  
> }  
> {  
> value: Kombiverkehr Strasse-Schiene,  
> Betontransporte  
> }  
> {  
> value: Kombiverkehr Strasse-Schiene,  
> Festbrennstofftransporte  
> }  
> ]  
> }  
> highlight: {  
> denotation: [  
> _Schienenpersonenfernverkehr_ (SPFV)  
> ]  
> }  
> }  
> ]  
> }}
> 
> I wonder why the denotation ""Schienenpersonenfernverkehr" is  
> highlighted when it just matched with 1 token (_schien_). If i  
> separate my query into 2 queries, one for nested object only and one  
> for query on denotation, both work fine.
> 
> The result I expected is:  
> {  
> took: 2  
> timed\_out: false  
> \_shards: {  
> total: 5  
> successful: 5  
> failed: 0  
> }  
> hits: {  
> total: 1  
> max\_score: 0.57735026  
> hits: [  
> {  
> \_index: business  
> \_type: product  
> \_id: 1  
> \_score: 0.57735026  
> \_source: {  
> productKey: 1  
> denotation: Schienenpersonenfernverkehr (SPFV)  
> alias: [  
> {  
> value: Kombiverkehr, Strasse-Schiene  
> }  
> {  
> value: Kombiverkehr Strasse-Schiene,  
> Containertransporte  
> }  
> {  
> value: Kombiverkehr Strasse-Schiene,  
> Betontransporte  
> }  
> {  
> value: Kombiverkehr Strasse-Schiene,  
> Festbrennstofftransporte  
> }  
> ]  
> }  
> }  
> ]  
> }
> 
> }
> 
> If anyone could help me on this, it's really appriciated, thanks so  
> much.
> 
> anhthu

---

<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:34am UTC](https://discuss.elastic.co/t/highlight-works-incorrectly/7069/3 "2017-07-06T03:34:42Z")

</div>


