Issue 1:
Elasticsearch version: 2.3

JVM version: 1.8.0_25

OS version: OSX 10.11.5

Description of the problem including expected versus actual behavior:

Steps to reproduce:

Define a nested object type in your mapping

Index some documents

Perform a nested query with a query_string on on of the field of the nested object using a wildcard

I am indexing the following document with a nested type locations:

curl -X PUT 'http://localhost:9201/test_nested?pretty' -d '{
"settings": {
"index": {
"number_of_shards": 5,
"number_of_replicas": 1
}
},
"mappings": {
"loc": {
"properties": {
"id": {
"type": "string",
"index": "not_analyzed"
},
"locations": {
"type": "nested",
"properties": {
"input": {
"type": "string",
"index": "not_analyzed"
},
"country_code": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
}
}'

curl -X PUT 'http://localhost:9201/test_nested/loc/location_1' -d '{
id: "location_1",
"locations": [
{
input: "xxx",
country_code: "BE"
},
{
input: "yyy",
country_code: "NL"
}
]
}'

curl -X PUT 'http://localhost:9201/test_nested/loc/location_2' -d '{
id: "location_2",
"locations": [
{
input: "zzz",
country_code: "BR"
},
{
input: "vvv",
country_code: "US"
}
]
}'

When i try todo an extact match using query_string it works:

curl -X POST 'http://localhost:9201/test_nested/_search' -d '
{
"query": {
"nested": {
"path": "locations",
"query": {
"query_string": {
"fields": [
"locations.country_code"
],
"query": "BE"
}
}
}
}
}
'

RESULT:

{"took":1,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":1,"max_score":2.098612,"hits":[{"_index":"test_nested","_type":"loc","_id":"location_1","_score":2.098612,"_source":{
id: "location_1",
"locations": [
{
input: "xxx",
country_code: "BE"
},
{
input: "yyy",
country_code: "NL"
}

When i try todo a wildcard it does not return anything:

curl -X POST 'http://localhost:9201/test_nested/_search' -d '
{
"query": {
"nested": {
"path": "locations",
"query": {
"query_string": {
"fields": [
"locations.country_code"
],
"query": "B*"
}
}
}
}
}
'

RESULT:

{"took":1,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":0,"max_score":null,"hits":[]}}

It seems to only not be working for nested datatypes because if i do a query_string with a wildcard on a property of the main document it works as expected:

curl -X POST 'http://localhost:9201/test_nested/_search' -d '
{
"query": {
"query_string": {
"fields": [
"id"
],
"query": "location_*"
}
}
}
'

RESULT:

{"took":1,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":2,"max_score":1.0,"hits":[{"_index":"test_nested","_type":"loc","_id":"location_1","_score":1.0,"_source":{
id: "location_1",
"locations": [
{
input: "xxx",
country_code: "BE"
},
{
input: "yyy",
country_code: "NL"
}
]
}},{"_index":"test_nested","_type":"loc","_id":"location_2","_score":1.0,"_source":{
id: "location_2",
"locations": [
{
input: "zzz",
country_code: "BR"
},
{
input: "vvv",
country_code: "US"
}
]
}}]}}

So is this a limitation of the nested datatype that it does not work with wildcard when using query_string? And if yes where is it documented? The weird thing is as well if i do a wildcard query it seems to work as well.

curl -X POST 'http://localhost:9201/test_nested/_search' -d '
{
"query": {
"nested": {
"path": "locations",
"query": {
"wildcard": {
"locations.country_code": "B*"
}
}
}
}
}
'

{"took":1,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":2,"max_score":1.0,"hits":[{"_index":"test_nested","_type":"loc","_id":"location_1","_score":1.0,"_source":{
id: "location_1",
"locations": [
{
input: "xxx",
country_code: "BE"
},
{
input: "yyy",
country_code: "NL"
}
]
}},{"_index":"test_nested","_type":"loc","_id":"location_2","_score":1.0,"_source":{
id: "location_2",
"locations": [
{
input: "zzz",
country_code: "BR"
},
{
input: "vvv",
country_code: "US"
}
]
}}]}}

Issue 2:
for the record, i think we should remove this lowercasing option completely in parsers, disable it, and let the analysis chain take care. For multitermqueries, its a little tricky, which subset of the filters should be used? For example lowercasing is reasonable, stemming is not.

But lucene already annotates each analyzer component deemed to be "reasonable" for wildcards with a marker interface (MultiTermAwareComponent). Things like lowercasefilter have it and things like stemmers dont have it. This is enough to build a "chain", automatically from the query analyzer, that acts reasonably for multitermqueries.

I know we don't use the lucene factories (es has its own), but we have a table that maps between them, i know because its in a test I wrote. So the information is there :)

All queryparsers have hooks (e.g. factory methods for prefix/wildcard/range) that make it possible to use this, for example solr does it by default, as soon as it did this, people stopped complaining about confusing behavior: both for the unanalyzed, and the analyzed case. it just works.

Sorry for the long explanation.

Compare:

http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/analysis/common/src/java/org/apache/lucene/analysis/core/LowerCaseFilterFactory.java?view=markup

http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/analysis/common/src/java/org/apache/lucene/analysis/en/PorterStemFilterFactory.java?view=markup