Correctly analyzed field not found by query_string search

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/' -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'
-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' -d
'{"name":"pharmacy_docs"}'

SEARCH "pharmacy"

curl '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'

{
"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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/5387ebce-9b07-4d08-8f50-b83f7f44823f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

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' -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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/352b95b7-0651-4d1e-88e1-44be6ebf2e6b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.