# Search and index analyzer not working as expected

**URL:** <https://discuss.elastic.co/t/search-and-index-analyzer-not-working-as-expected/5554>\
**Category:** Elasticsearch\
**Created:** [October 10, 2011, 10:40pm UTC](https://discuss.elastic.co/t/search-and-index-analyzer-not-working-as-expected/5554 "2011-10-10T22:40:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![James\_Wilson](https://avatars.discourse-cdn.com/v4/letter/j/53a042/32.png) [@James\_Wilson](https://discuss.elastic.co/u/James_Wilson)\
**Post date:** [October 10, 2011, 10:40pm UTC](https://discuss.elastic.co/t/search-and-index-analyzer-not-working-as-expected/5554/1 "2011-10-10T22:40:09Z")

</div>

Short description: searching by the stem word works ("meet") but using  
the word in the source document ("meeting") doesn't. I'm missing  
something here that's probably fundamental, but it's not explained  
anywhere.

I thought a query of "meeting" would be stemmed to "meet" and then it  
would find a document that was analyzed the same way at index time.

elasticsearch.yml:

index:  
analysis:  
analyzer:  
my\_analyzer: # duplicate the snowball analyzer  
type: custom  
tokenizer: standard  
filter: [standard, lowercase, stop, snowball]

Setup:

curl -XPUT '[http://localhost:9200/twitter](http://localhost:9200/twitter)'  
curl -XPUT '[http://localhost:9200/twitter/tweet/\_mapping](http://localhost:9200/twitter/tweet/_mapping)' -d '  
{"tweet" : { "search\_analyzer": "my\_analyzer", "index\_analyzer":  
"my\_analyzer", "properties": { "user": { "type": "string" },  
"message": {"type": "string" } } } }'  
curl -XPUT '[http://localhost:9200/twitter/tweet/1](http://localhost:9200/twitter/tweet/1)' -d '  
{"user": "bob", "message": "team meeting"}'

Queries:

curl -XGET '[http://localhost:9200/twitter/tweet/\_search](http://localhost:9200/twitter/tweet/_search)' -d '  
{"query" : {"text": {"\_all": "meeting"} } }'  
--\> no results

curl -XGET '[http://localhost:9200/twitter/tweet/\_search](http://localhost:9200/twitter/tweet/_search)' -d '  
{"query" : {"text": {"\_all": "meet"} } }'  
--\> returns the document

---

<div class="post-metadata">

**Author:** ![erlo](https://avatars.discourse-cdn.com/v4/letter/e/f07891/32.png) [@erlo](https://discuss.elastic.co/u/erlo)\
**Post date:** [October 11, 2011, 7:09am UTC](https://discuss.elastic.co/t/search-and-index-analyzer-not-working-as-expected/5554/2 "2011-10-11T07:09:08Z")

</div>

If you want to search on the special \_all field it seems that you should  
specify the analyzer in the query too:

Try this:

curl -XGET '[http://localhost:9200/twitter/tweet/\_search](http://localhost:9200/twitter/tweet/_search)' -d '  
{  
"query":{  
"text":{  
"\_all":{  
"query":"meeting",  
"analyzer":"my\_analyzer"  
}  
}  
}  
}'

James Wilson wrote:

> Short description: searching by the stem word works ("meet") but using  
> the word in the source document ("meeting") doesn't. I'm missing  
> something here that's probably fundamental, but it's not explained  
> anywhere.
> 
> I thought a query of "meeting" would be stemmed to "meet" and then it  
> would find a document that was analyzed the same way at index time.
> 
> elasticsearch.yml:
> 
> index:  
> analysis:  
> analyzer:  
> my\_analyzer: # duplicate the snowball analyzer  
> type: custom  
> tokenizer: standard  
> filter: [standard, lowercase, stop, snowball]
> 
> Setup:
> 
> curl -XPUT '[http://localhost:9200/twitter](http://localhost:9200/twitter)'  
> curl -XPUT '[http://localhost:9200/twitter/tweet/\_mapping](http://localhost:9200/twitter/tweet/_mapping)' -d '  
> {"tweet" : { "search\_analyzer": "my\_analyzer", "index\_analyzer":  
> "my\_analyzer", "properties": { "user": { "type": "string" },  
> "message": {"type": "string" } } } }'  
> curl -XPUT '[http://localhost:9200/twitter/tweet/1](http://localhost:9200/twitter/tweet/1)' -d '  
> {"user": "bob", "message": "team meeting"}'
> 
> Queries:
> 
> curl -XGET '[http://localhost:9200/twitter/tweet/\_search](http://localhost:9200/twitter/tweet/_search)' -d '  
> {"query" : {"text": {"\_all": "meeting"} } }'  
> --\> no results
> 
> curl -XGET '[http://localhost:9200/twitter/tweet/\_search](http://localhost:9200/twitter/tweet/_search)' -d '  
> {"query" : {"text": {"\_all": "meet"} } }'  
> --\> returns the document

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [October 12, 2011, 8:54pm UTC](https://discuss.elastic.co/t/search-and-index-analyzer-not-working-as-expected/5554/3 "2011-10-12T20:54:44Z")

</div>

Heya,

When searching "against a type", matching docs automatically gets  
filtered only for that type, but, search\_analyzer associated with that type  
is not applied. It should be, btw, opened an issue:  
[When searching against an index/type, use the type information to derive different search aspects · Issue #1391 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/1391). For now, you can  
explicitly specify the analyzer, or, specify the analyzer as the default  
analyzer for that _index_ (Across types), by simply renaming my\_analyzer to  
default.

-shay.banon

On Tue, Oct 11, 2011 at 12:40 AM, James Wilson [jwilson556@gmail.com](mailto:jwilson556@gmail.com) wrote:

> Short description: searching by the stem word works ("meet") but using  
> the word in the source document ("meeting") doesn't. I'm missing  
> something here that's probably fundamental, but it's not explained  
> anywhere.
> 
> I thought a query of "meeting" would be stemmed to "meet" and then it  
> would find a document that was analyzed the same way at index time.
> 
> elasticsearch.yml:
> 
> index:  
> analysis:  
> analyzer:  
> my\_analyzer: # duplicate the snowball analyzer  
> type: custom  
> tokenizer: standard  
> filter: [standard, lowercase, stop, snowball]
> 
> Setup:
> 
> curl -XPUT '[http://localhost:9200/twitter](http://localhost:9200/twitter)'  
> curl -XPUT '[http://localhost:9200/twitter/tweet/\_mapping](http://localhost:9200/twitter/tweet/_mapping)' -d '  
> {"tweet" : { "search\_analyzer": "my\_analyzer", "index\_analyzer":  
> "my\_analyzer", "properties": { "user": { "type": "string" },  
> "message": {"type": "string" } } } }'  
> curl -XPUT '[http://localhost:9200/twitter/tweet/1](http://localhost:9200/twitter/tweet/1)' -d '  
> {"user": "bob", "message": "team meeting"}'
> 
> Queries:
> 
> curl -XGET '[http://localhost:9200/twitter/tweet/\_search](http://localhost:9200/twitter/tweet/_search)' -d '  
> {"query" : {"text": {"\_all": "meeting"} } }'  
> --\> no results
> 
> curl -XGET '[http://localhost:9200/twitter/tweet/\_search](http://localhost:9200/twitter/tweet/_search)' -d '  
> {"query" : {"text": {"\_all": "meet"} } }'  
> --\> returns the document

---

<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 6, 2017, 3:52am UTC](https://discuss.elastic.co/t/search-and-index-analyzer-not-working-as-expected/5554/4 "2017-07-06T03:52:15Z")

</div>


