# Stop words are not working

**URL:** <https://discuss.elastic.co/t/stop-words-are-not-working/53149>\
**Category:** Elasticsearch\
**Created:** [June 17, 2016, 11:48am UTC](https://discuss.elastic.co/t/stop-words-are-not-working/53149 "2016-06-17T11:48:16Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ramz](https://avatars.discourse-cdn.com/v4/letter/r/a183cd/32.png) [@ramz](https://discuss.elastic.co/u/ramz)\
**Post date:** [June 17, 2016, 11:48am UTC](https://discuss.elastic.co/t/stop-words-are-not-working/53149/1 "2016-06-17T11:48:16Z")

</div>

Hello EveryOne,

I just started with elastic search. Its quite interesting and joy to learn.

However i have been stuck implementing the stopwords.

Here's my index:

url -XPUT '[http://localhost:9200/my\_indice](http://localhost:9200/my_indice)' -d'  
{  
"settings": {  
"analysis": {  
"char\_filter": {  
"&\_to\_and": {  
"type": "mapping",  
"mappings": ["&=\> and "]  
}},  
"filter": {  
"my\_stopwords": {  
"type": "stop",  
"stopwords": ["the", "a" ,"from" ,"is"]  
}},  
"analyzer": {  
"my\_analyzer": {  
"type": "custom",  
"char\_filter": ["html\_strip", "&\_to\_and"],  
"tokenizer": "whitespace",  
"filter": ["lowercase", "my\_stopwords"]  
}}  
}}}'

and here are my mappings:

curl -XPUT '[http://localhost:9200/my\_indice/\_mapping/test](http://localhost:9200/my_indice/_mapping/test)' -d '  
{  
"properties": {  
"tags": {  
"type": "string",  
"analyzer": "my\_analyzer"  
},  
"displayName": {  
"type": "string"  
}  
}'

I have cross checked whether my custom analyzer is working , here's the result:

curl -XGET '[http://localhost:9200/my\_indice/\_analyze?analyzer=my\_analyzer](http://localhost:9200/my_indice/_analyze?analyzer=my_analyzer)' -d '  
The quick & brown is a fox'

"tokens": [{  
"token": "quick",  
"start\_offset": 5,  
"end\_offset": 10,  
"type": "word",  
"position": 2  
}, {  
"token": "and",  
"start\_offset": 11,  
"end\_offset": 12,  
"type": "word",  
"position": 3  
}, {  
"token": "brown",  
"start\_offset": 13,  
"end\_offset": 18,  
"type": "word",  
"position": 4  
}, {  
"token": "fox",  
"start\_offset": 24,  
"end\_offset": 27,  
"type": "word",  
"position": 7  
}]  
}

So it clearly shows that custom analyzer is working.

But when i search for documents , it's retrieving documents containing "the".

Here's my query:

curl -XPUT '[http://localhost:9200/my\_indice/test](http://localhost:9200/my_indice/test)' -d '  
'{  
"query": {  
"match": {  
"allTags": "the"  
}  
}  
}'

I want to know whether i skipped anything or is there any mistake either with my mappings or query.

thanks,  
Ram.

---

<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:** [June 17, 2016, 12:25pm UTC](https://discuss.elastic.co/t/stop-words-are-not-working/53149/2 "2016-06-17T12:25:40Z")

</div>

Hey,

looks ok from a top level view. Can you include the index operations of the document as well? Also, the `allTags` field in the query example should be `tags` I guess?

--Alex

---

<div class="post-metadata">

**Author:** ![ramz](https://avatars.discourse-cdn.com/v4/letter/r/a183cd/32.png) [@ramz](https://discuss.elastic.co/u/ramz)\
**Post date:** [June 17, 2016, 12:39pm UTC](https://discuss.elastic.co/t/stop-words-are-not-working/53149/3 "2016-06-17T12:39:11Z")

</div>

Hi spinscale,

@it was my mistake while posting in the forum.

the query:

curl -XPUT '[http://localhost:9200/my\_indice/test](http://localhost:9200/my_indice/test)' -d '  
'{  
"query": {  
"match": {  
"tags": "the"  
}  
}  
}'

Here's the result i have been getting on running the query:

{  
"took": 2,  
"timed\_out": false,  
"\_shards": {  
"total": 1,  
"successful": 1,  
"failed": 0  
},  
"hits": {  
"total": 1,  
"max\_score": 1.1473356,  
"hits": [{  
"\_index": "my\_indice",  
"\_type": "test",  
"\_id": "1",  
"\_score": 1.1473356,  
"\_source": {  
"displayName": "Hyderabad Dum Biryani",  
"allTags": [  
"hyderabad dum biryani",  
"this is the best place to enjoy ur spicy biryani",  
"hyderabad"  
]  
}  
}]  
}  
}

---

<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:** [June 17, 2016, 12:51pm UTC](https://discuss.elastic.co/t/stop-words-are-not-working/53149/4 "2016-06-17T12:51:06Z")

</div>

now your returned hits contain an `allTags` field. Can you please provide a **full** reproducible example for other to debug? The exact calls to create the index, to index the documents and to query, all together.

---

<div class="post-metadata">

**Author:** ![ramz](https://avatars.discourse-cdn.com/v4/letter/r/a183cd/32.png) [@ramz](https://discuss.elastic.co/u/ramz)\
**Post date:** [June 18, 2016, 4:15am UTC](https://discuss.elastic.co/t/stop-words-are-not-working/53149/5 "2016-06-18T04:15:30Z")

</div>

Hi @spinscale

thanks for your patience man.

Here's my complete work on stop words.

Custom Analyzer Creation for Stop Words:

curl -XPUT '[http://localhost:9200/myIndice](http://localhost:9200/myIndice)' -d'  
{  
"settings": {  
"analysis": {  
"char\_filter": {  
"&toand": {  
"type": "mapping",  
"mappings": ["&=\> and "]  
}},  
"filter": {  
"my\_stopwords": {  
"type": "stop",  
"stopwords": ["the", "a" ,"from" ,"is"]  
}},  
"analyzer": {  
"my\_analyzer": {  
"type": "custom",  
"char\_filter": ["html\_strip", "&\_to\_and"],  
"tokenizer": "whitespace",  
"filter": ["lowercase", "my\_stopwords"]  
}}  
}}}'

Mappings:

curl -XPUT '[http://localhost:9200/myIndice/\_mapping/test](http://localhost:9200/myIndice/_mapping/test)' -d '  
{  
"properties": {  
"allTags": {  
"type": "string",  
"analyzer": "my\_analyzer"  
},  
"displayName": {  
"type": "string"  
}  
}'

Analyzer Testing:

curl -XGET '[http://localhost:9200/myIndice/\_analyze?analyzer=my\_analyzer](http://localhost:9200/myIndice/_analyze?analyzer=my_analyzer)' -d '  
The quick & brown is a fox'

"tokens": [{  
"token": "quick",  
"start\_offset": 5,  
"end\_offset": 10,  
"type": "word",  
"position": 2  
}, {  
"token": "and",  
"start\_offset": 11,  
"end\_offset": 12,  
"type": "word",  
"position": 3  
}, {  
"token": "brown",  
"start\_offset": 13,  
"end\_offset": 18,  
"type": "word",  
"position": 4  
}, {  
"token": "fox",  
"start\_offset": 24,  
"end\_offset": 27,  
"type": "word",  
"position": 7  
}]  
}

Posting Data:

curl -XPOST '[http://localhost:9200/myIndice/test/1](http://localhost:9200/myIndice/test/1)' -d '  
{  
"displayName": "Hyderabad Dum Biryani",  
"allTags": ["hyderabad dum biryani","this is the best place to enjoy ur spicy biryani","hyderabad"]  
}'

Query:

curl -XGET '[http://localhost:9200/myIndice/test](http://localhost:9200/myIndice/test)' -d '  
'{  
"query": {  
"match": {  
"allTags": "the"  
}  
}  
}'

Result:

{  
"took": 2,  
"timed\_out": false,  
"\_shards": {  
"total": 1,  
"successful": 1,  
"failed": 0  
},  
"hits": {  
"total": 1,  
"max\_score": 1.1473356,  
"hits": [{  
"\_index": "myIndice",  
"\_type": "test",  
"\_id": "1",  
"\_score": 1.1473356,  
"\_source": {  
"displayName": "Hyderabad Dum Biryani",  
"allTags": [  
"hyderabad dum biryani",  
"this is the best place to enjoy ur spicy biryani",  
"hyderabad"  
]  
}  
}]  
}  
}

Do i Need to explicitly add filter for allTags while creating mappings?

regards,  
Ram

---

<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:** [June 20, 2016, 1:58pm UTC](https://discuss.elastic.co/t/stop-words-are-not-working/53149/6 "2016-06-20T13:58:02Z")

</div>

Hey,

did you really try this example out? The mapping is broken, its name is wrong as it is missing underscores, the index name contains upper case characters and wont be created in 2.x releases, your 'search' operation is a PUT to a type.

Please ensure your example is actually testable.

--Alex

---

<div class="post-metadata">

**Author:** ![ramz](https://avatars.discourse-cdn.com/v4/letter/r/a183cd/32.png) [@ramz](https://discuss.elastic.co/u/ramz)\
**Post date:** [June 21, 2016, 4:37am UTC](https://discuss.elastic.co/t/stop-words-are-not-working/53149/7 "2016-06-21T04:37:16Z")

</div>

Hi spinacle ,

am using AWS elastic search.Its version is 1.5.2.

I dont have an option to upgrade elastic to current 2.2 in AWS.

regarding the example: I have implemented and tested it except that i gave GET method instead of PUT in my example.

Is it based on the versions , will the implementations change?

regards,  
Ram.

---

<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, 10:41pm UTC](https://discuss.elastic.co/t/stop-words-are-not-working/53149/8 "2017-07-05T22:41:56Z")

</div>


