# Problem understanding phrase matching with stop words

**URL:** <https://discuss.elastic.co/t/problem-understanding-phrase-matching-with-stop-words/97847>\
**Category:** Elasticsearch\
**Created:** [August 22, 2017, 4:47am UTC](https://discuss.elastic.co/t/problem-understanding-phrase-matching-with-stop-words/97847 "2017-08-22T04:47:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![wmjb](https://avatars.discourse-cdn.com/v4/letter/w/76d3ee/32.png) [@wmjb](https://discuss.elastic.co/u/wmjb)\
**Post date:** [August 22, 2017, 4:47am UTC](https://discuss.elastic.co/t/problem-understanding-phrase-matching-with-stop-words/97847/1 "2017-08-22T04:47:09Z")

</div>

Hi,  
I have mapped an index as follows

```
PUT test
{
  "settings": {
    "index": {
      "number_of_shards": 1,
      "analysis": {
        "analyzer": {
          "english": {
            "tokenizer": "standard",
            "filter": ["trim", "lowercase", "english_possessive_stemmer", "my_stop", "light_english_stemmer","shingle"]
          }
        },
        "filter": {
          "english_possessive_stemmer":{
            "type" : "stemmer",
            "language" : "possessive_english"
          },
          "light_english_stemmer":{
            "type" : "stemmer",
            "language" : "light_english"
          },
          "my_stop":{
            "type" : "stop",
            "stopwords" : ["what", "is"],
            "remove_trailing" : "false"
          }
        }
      }
    }
  },
  "mappings": {
    "test": {
      "properties": {
        "title": {
          "type": "text",
          "analyzer": "english"
        }
      }
    }
  }
}

```

And inserted following documents

```
POST test/test?refresh=true
{"title": "hilton colombo"}
POST test/test?refresh=true
{"title": "colombo hilton"}

```

Now when I search for "what is hilton colombo" I do not get any results.

```
GET test/test/_search
{
  "query": {
    "match": {
      "title": {
        "query": "what is hilton colombo",
        "analyzer": "english",
        "operator": "and"
      }
    }
  }
}

```

But when I analyze the query I can see the "hilton colombo" as a token

```
GET test/_analyze
{
  "analyzer": "english",
  "text": "what is hilton colombo"
}

```

Shouldn't the search analyzer remove any stop words and match the rest of the words against the document titles?

What am I missing here?

Can anyone please help me to figure this one out? Thank you 🙂

---

<div class="post-metadata">

**Author:** ![abdon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdon/32/9195_2.png) [@abdon](https://discuss.elastic.co/u/abdon)\
**Post date:** [August 24, 2017, 9:51am UTC](https://discuss.elastic.co/t/problem-understanding-phrase-matching-with-stop-words/97847/2 "2017-08-24T09:51:45Z")

</div>

What's causing this behavior is using a combination of the `stop` and `shingle` filters. Take a look at the first token in the response of your `_analyze` request:

```
  "token": "_ hilton",
  "start_offset": 8,
  "end_offset": 14,
  "type": "shingle",
  "position": 0,
  "positionLength": 2

```

The underscore in that token is the "filler token": the string that gets inserted wherever a stop word was removed. Because your documents do not have those stop words, there is no token `_ hilton` in the index for your documents, and because you are using an `and` operator, you're not matching any documents as a result.

One way to resolve this would be to define the `filler_token` to be `""` in the `shingle` filter and move the `strip` filter to the end of the chain:

```
PUT test
{
  "settings": {
    "index": {
      "number_of_shards": 1,
      "analysis": {
        "analyzer": {
          "english": {
            "tokenizer": "standard",
            "filter": ["lowercase", "english_possessive_stemmer", "my_stop", "light_english_stemmer","my_shingle", "trim"]
          }
        },
        "filter": {
          "english_possessive_stemmer":{
            "type" : "stemmer",
            "language" : "possessive_english"
          },
          "light_english_stemmer":{
            "type" : "stemmer",
            "language" : "light_english"
          },
          "my_stop":{
            "type" : "stop",
            "stopwords" : ["what", "is"],
            "remove_trailing" : "false"
          },
          "my_shingle":{
            "type": "shingle",
            "filler_token": ""
          }
        }
      }
    }
  },
  "mappings": {
    "test": {
      "properties": {
        "title": {
          "type": "text",
          "analyzer": "english"
        }
      }
    }
  }
}
```

---

<div class="post-metadata">

**Author:** ![wmjb](https://avatars.discourse-cdn.com/v4/letter/w/76d3ee/32.png) [@wmjb](https://discuss.elastic.co/u/wmjb)\
**Post date:** [August 24, 2017, 11:48am UTC](https://discuss.elastic.co/t/problem-understanding-phrase-matching-with-stop-words/97847/3 "2017-08-24T11:48:46Z")

</div>

Thank you very much @abdon. I didnt know about the `filler_token`. Cheers 🙂

---

<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 21, 2017, 11:48am UTC](https://discuss.elastic.co/t/problem-understanding-phrase-matching-with-stop-words/97847/4 "2017-09-21T11:48:48Z")

</div>

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