# Stop phrases rather words

**URL:** <https://discuss.elastic.co/t/stop-phrases-rather-words/108058>\
**Category:** Elasticsearch\
**Created:** [November 17, 2017, 4:57am UTC](https://discuss.elastic.co/t/stop-phrases-rather-words/108058 "2017-11-17T04:57:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![AmitG](https://avatars.discourse-cdn.com/v4/letter/a/9dc877/32.png) [@AmitG](https://discuss.elastic.co/u/AmitG)\
**Post date:** [November 17, 2017, 4:57am UTC](https://discuss.elastic.co/t/stop-phrases-rather-words/108058/1 "2017-11-17T04:57:47Z")

</div>

Hi, I am sure this would have been discussed earlier but not able to find much. We have a requirement to exclude phrase rather than individual word e.g. if name is 'Big Elephant', it should be excluded but it is either 'Big' or "Elephant' or includes other words, they must not be filtered. Is there a way to use phrases in the stopword file.

cheers,  
Amit

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [November 24, 2017, 9:35pm UTC](https://discuss.elastic.co/t/stop-phrases-rather-words/108058/2 "2017-11-24T21:35:39Z")

</div>

I think you can do that with combination of synonym filter and stop words.

```auto
DELETE test

PUT test
{
  "settings": {
    "analysis": {
      "filter": {
        "phrase_matcher": {
          "type": "synonym",
          "synonyms": [
            "big elephant, small giraffe => stop_me"
          ]
        },
        "my_stop": {
          "type": "stop",
          "stopwords": [
            "stop_me"
          ]
        }
      },
      "analyzer": {
        "stop_phrase": {
          "tokenizer": "standard",
          "fitler": [
            "lowercase",
            "phrase_matcher",
            "stop"
          ]
        }
      }
    }
  },
  "mappings": {
    "doc": {
      "properties": {
        "text" : {
          "type": "text",
          "analyzer": "stop_phrase"
        }
      }
    }
  }
}

POST /test/doc/_bulk?refresh
{ "index" : { "_id" : "1" } }
{ "text" : "A big elephant and a very small giraffe" }
{ "index" : { "_id" : "1" } }
{ "text" : "A very small elephant and a big giraffe" }

GET /test/doc/_search
{
  "query": {
    "match": {
      "text": "elephant"
    }
  }
}

GET /test/doc/_search
{
  "query": {
    "match": {
      "text": "big elephant"
    }
  }
}

GET /test/doc/_search
{
  "query": {
    "match_phrase": {
      "text": "small elephant"
    }
  }
}

```

---

<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:** [December 22, 2017, 9:35pm UTC](https://discuss.elastic.co/t/stop-phrases-rather-words/108058/3 "2017-12-22T21:35:53Z")

</div>

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