# Highlight stopwords in hits

**URL:** <https://discuss.elastic.co/t/highlight-stopwords-in-hits/194636>\
**Category:** Elasticsearch\
**Created:** [August 9, 2019, 2:30pm UTC](https://discuss.elastic.co/t/highlight-stopwords-in-hits/194636 "2019-08-09T14:30:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![fedoroko](https://avatars.discourse-cdn.com/v4/letter/f/977dab/32.png) [@fedoroko](https://discuss.elastic.co/u/fedoroko)\
**Post date:** [August 9, 2019, 2:31pm UTC](https://discuss.elastic.co/t/highlight-stopwords-in-hits/194636/1 "2019-08-09T14:31:00Z")

</div>

Hey, what is the best way to skip stopwords in query but highlight them in hits?

Current settings:

```
'settings': {
    'analysis': {
        'analyzer':{
            my_analyzer:{
                'tokenizer':'standard',
                'filter':{
                    'lowercase',
                    'my_snowball_en',
                    'english_stop',
                }
            }
        },
        'filter':{
            'my_snowball_en':{
                'type':'sbowball',
                'language':'english',
            },
            'english_stop':{
                'type':'stop',
                'stopwords':'english'
            }
        }
    }
},
'mappings':{
    'properties':{
        'title':{
            'type':'text',
            'fields':{
                'en':{
                    'type':'text',
                    'analyzer':'my_analyzer'
                }
            }
        }
    }
}

```

search:

```
'query':{
    'bool':{
        'must':{
            'multi_match':{
                'type':'bool_prefix',
                'query':'some_query',
                'fuzziness':'1',
                'prefix_lenght':'2,
                'fields':{
                    'title',
                    'others'
                },
                'minimum_should_match':'80%',
            },
            'match':{
                'status':'3',
            },
        }
    }
},
'highlight':{
    'pre,post,nub_of_frag,etc...'
    'fields':{
        'title',
        'others'
    }
}

```

with query: 'the cheese for the red fox ', it highlights **cheese red fox**.

Tried to build highlight\_query but it returns nothing:

```
'highlight':{
    'highlight_query':{
        'bool':{
            'should':{
                'match_phrase':{
                    'title':'similar to search query'
                }
            }
        }
    }
}

```

What can i do in this case?

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [August 12, 2019, 8:42am UTC](https://discuss.elastic.co/t/highlight-stopwords-in-hits/194636/2 "2019-08-12T08:42:30Z")

</div>

Hey,

have you tried using a different field for the highlight query. I have an example here (though I might be missing something)

```auto
DELETE test

PUT test
{
  "mappings": {
    "properties": {
      "text": {
        "type": "text",
        "fields": {
          "stop": {
            "type": "text",
            "analyzer": "stop"
          }
        }
      }
    }
  }
}

PUT test/_doc/1
{
  "text" : "this is an awesome test and some more"
}

GET test/_analyze
{
  "text" : "this is an awesome test and some more"
}

GET test/_analyze
{
  "text" : "this is an awesome test and some more",
  "field": "text.stop"
}

GET test/_search
{
  "query": {
    "match": {
      "text.stop": {
        "query": "this is an awesome test",
        "operator": "and"
      }
    }
  },
  "highlight": {
    "fields": {
      "text": {
        "highlight_query": {
          "match": {
            "text": "an awesome test"
          }
        }
      }
    }
  }
}

```

--Alex

---

<div class="post-metadata">

**Author:** ![fedoroko](https://avatars.discourse-cdn.com/v4/letter/f/977dab/32.png) [@fedoroko](https://discuss.elastic.co/u/fedoroko)\
**Post date:** [August 13, 2019, 9:00am UTC](https://discuss.elastic.co/t/highlight-stopwords-in-hits/194636/3 "2019-08-13T09:00:05Z")

</div>

Yes, it doesn't work for me. And anyway i guess it's a bad option to highlight by original query string because it can have mistakes, so we will get hits thanks to fuzzy but highlights will be 0. Am i right?

Is there any other solution?

Thank you for answer anyway.

---

<div class="post-metadata">

**Author:** ![fedoroko](https://avatars.discourse-cdn.com/v4/letter/f/977dab/32.png) [@fedoroko](https://discuss.elastic.co/u/fedoroko)\
**Post date:** [August 14, 2019, 10:48am UTC](https://discuss.elastic.co/t/highlight-stopwords-in-hits/194636/4 "2019-08-14T10:48:49Z")

</div>

Figured out how to use highlight\_query it works but because of fuzziness 'AUTO' words with 2 or less letters don't highlight. I can't delete fuzziness cause query may contain mistakes. What options do i have?

Current query:

```
'query':{
    'bool':{
        'must':{
            'multi_match':{
                'type':'best_fields',
                'query':'some_query',
                'fuzziness':'AUTO',
                'fields':{
                    'title.en',
                    'others'
                },
                'minimum_should_match':'80%',
            },
            'match':{
                'status':'3',
            },
        }
    }
},
'highlight':{
    'pre,post,num_of_frag,etc...'
    'fields':{
        'title': {
            'highlight_query':{
                'match':{
                    'title':{
                        'query': 'similar to original query',
                        'fuzziness': 'AUTO',
                        //standard analyzer without stopwords
                        'analyzer': 'standard'
                    }
                }
            }
        },
        'others'
    }
}

```

with query "effect of a fox" it highlights " **effect** of a **fox**".

Also tried to use shingle [min2; max2] with my\_analyzer from original post. In this case i can just highlight by 'title.en' field (without highlight\_query), but the result is unpredictable.

For example with query _"in connection with the development"_ it highlights _"The article deals with the problems arising in **connection with the development of** curricula for basic educational programs based..."_.

In this text \_analyze shows next tokens: [\_ connect][connect][connect \_][\_develop][develop][develop \_] so in my opinion it should returns: "\_(in) connection \_(with) \_(the) development \_(of)" but in highlights return "in" was cut out. Can someone explain why it works like this?

---

<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:** [September 11, 2019, 10:48am UTC](https://discuss.elastic.co/t/highlight-stopwords-in-hits/194636/5 "2019-09-11T10:48:50Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
