# Correctly analyzed field not found by query\_string search

**URL:** <https://discuss.elastic.co/t/correctly-analyzed-field-not-found-by-query-string-search/22644>\
**Category:** Elasticsearch\
**Created:** [March 12, 2015, 8:37pm UTC](https://discuss.elastic.co/t/correctly-analyzed-field-not-found-by-query-string-search/22644 "2015-03-12T20:37:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ryan\_Pedela](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ryan_pedela/32/27156_2.png) [@Ryan\_Pedela](https://discuss.elastic.co/u/Ryan_Pedela)\
**Post date:** [March 12, 2015, 8:37pm UTC](https://discuss.elastic.co/t/correctly-analyzed-field-not-found-by-query-string-search/22644/1 "2015-03-12T20:37:04Z")

</div>

I am having an issue searching a field which was analyzed with a pattern  
analyzer. I have verified that the analyzer works correctly and the index  
contains the correct tokens. However when I search using query\_string, it  
does not return any results for the field. The field contains  
"pharmacy\_docs" which is correctly tokenized to ["pharmacy", "docs"], but  
when I search "pharmacy" no results are found. However if I use a term  
query, then I get correct results. What am I doing wrong?

I am using 1.4.2 and here is how to reproduce.

## CREATE INDEX

curl -XPUT '[http://localhost:9200/my\_index/](http://localhost:9200/my_index/)' -d '{  
"settings" : {  
"index" : {  
"number\_of\_shards" : 1,  
"number\_of\_replicas" : 0,  
"analysis" : {  
"analyzer" : {  
"name\_analyzer" : {  
"pattern" : "[\_\W]+",  
"type" : "pattern"  
}  
}  
}  
}  
}  
},  
"mappings" : {  
"default" : {  
"properties" : {  
"name" : {  
"type" : "string",  
"index": "analyzed",  
"analyzer" : "name\_analyzer"  
}  
}  
}  
}  
}'

## ANALYZE

curl  
'[http://localhost:9200/my\_index/\_analyze?pretty=1&analyzer=name\_analyzer](http://localhost:9200/my_index/_analyze?pretty=1&analyzer=name_analyzer)'  
-d 'pharmacy\_docs'

{  
"tokens" : [  
{  
"token" : "pharmacy",  
"start\_offset" : 0,  
"end\_offset" : 8,  
"type" : "word",  
"position" : 1  
},  
{  
"token" : "docs",  
"start\_offset" : 9,  
"end\_offset" : 13,  
"type" : "word",  
"position" : 2  
}  
]  
}

## INDEX DOCUMENT

curl -XPUT '[http://localhost:9200/my\_index/default/1](http://localhost:9200/my_index/default/1)' -d  
'{"name":"pharmacy\_docs"}'

## SEARCH "pharmacy"

curl '[http://localhost:9200/my\_index/\_search?q=pharmacy&pretty](http://localhost:9200/my_index/_search?q=pharmacy&pretty)'

{  
"took" : 3,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 1,  
"successful" : 1,  
"failed" : 0  
},  
"hits" : {  
"total" : 0,  
"max\_score" : null,  
"hits" : []  
}  
}

## SEARCH "pharmacy\_docs"

curl '[http://localhost:9200/my\_index/\_search?q=pharmacy\_docs&pretty](http://localhost:9200/my_index/_search?q=pharmacy_docs&pretty)'

{  
"took" : 13,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 1,  
"successful" : 1,  
"failed" : 0  
},  
"hits" : {  
"total" : 1,  
"max\_score" : 0.30685282,  
"hits" : [  
{  
"\_index" : "my\_index",  
"\_type" : "default",  
"\_id" : "1",  
"\_score" : 0.30685282,  
"\_source":{"name":"pharmacy\_docs"}  
}  
]  
}  
}

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/5387ebce-9b07-4d08-8f50-b83f7f44823f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/5387ebce-9b07-4d08-8f50-b83f7f44823f%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Ryan\_Pedela](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ryan_pedela/32/27156_2.png) [@Ryan\_Pedela](https://discuss.elastic.co/u/Ryan_Pedela)\
**Post date:** [March 17, 2015, 10:53pm UTC](https://discuss.elastic.co/t/correctly-analyzed-field-not-found-by-query-string-search/22644/2 "2015-03-17T22:53:03Z")

</div>

For anyone who has a similar problem, I have figured out the issue. By  
default, it appears to me that only the \_all field is searched. The \_all  
field contains "pharmacy\_docs" but not "pharmacy". If the search is  
modified to search the "name" fields then the search works. And if you  
wanted to support searching for "pharmacy\_docs", you could add "\_all" to  
the list such as:

curl '[http://localhost:9200/my\_index/\_search?pretty](http://localhost:9200/my_index/_search?pretty)' -d '{  
"query": {  
"query\_string": {  
"fields": ["\_all", "name"],  
"query": "pharmacy\_docs"  
}  
}  
}'

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/352b95b7-0651-4d1e-88e1-44be6ebf2e6b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/352b95b7-0651-4d1e-88e1-44be6ebf2e6b%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 12:26am UTC](https://discuss.elastic.co/t/correctly-analyzed-field-not-found-by-query-string-search/22644/3 "2017-07-06T00:26:04Z")

</div>


