# Unexpected highlighting

**URL:** <https://discuss.elastic.co/t/unexpected-highlighting/28348>\
**Category:** Elasticsearch\
**Created:** [August 31, 2015, 10:50am UTC](https://discuss.elastic.co/t/unexpected-highlighting/28348 "2015-08-31T10:50:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Settler](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/settler/32/3743_2.png) [@Settler](https://discuss.elastic.co/u/Settler)\
**Post date:** [August 31, 2015, 10:50am UTC](https://discuss.elastic.co/t/unexpected-highlighting/28348/1 "2015-08-31T10:50:36Z")

</div>

Hello.

I don't understand highlighting logic of elasticsearch.  
Here is my test:  
Elasticsearch 1.7.1  
Query:

```
{
    "query":{  
      "span_near":{  
         "clauses":[  
            {  
               "span_term":{  
                  "Text":{  
                     "value":"Test1"
                  }
               }
            },
            {  
               "span_or":{  
                  "clauses":[  
                     {  
                        "span_term":{  
                           "Text":{  
                              "value":"test2"
                           }
                        }
                     },
                     {  
                        "span_near":{  
                           "clauses":[  
                              {  
                                 "span_term":{  
                                    "Text":{  
                                       "value":"foo"
                                    }
                                 }
                              },
                              {  
                                 "span_term":{  
                                    "Text":{  
                                       "value":"test3"
                                    }
                                 }
                              }
                           ],
                           "slop":1,
                           "in_order":true
                        }
                     }
                  ]
               }
            }
         ],
         "slop":20,
         "in_order":false
      }
   },
    "highlight" : {
        "fields" : {
            "*" : {}
        }
    }
}

```

**Example 1:**  
Text: "Test1 test3 test2"  
Highlighting response: "`<em>Test1</em> <em>test3</em> <em>test2</em>`"  
Highlight term "test3" is not expected, because in query there is span\_near with two terms.

**Example 2:**  
Text: "Test1 test2 test3"  
Highlighting response will be: "`<em>Test1</em> <em>test2</em> test3`"  
"test3" here is not highlighted.

Could someone explain me why "test3" is highlighted in first example?  
P.S. In tests used plain highlighter.

---

<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:53pm UTC](https://discuss.elastic.co/t/unexpected-highlighting/28348/2 "2017-07-05T23:53:05Z")

</div>


