<p dir="auto"><strong>Elasticsearch version</strong>: 2.3</p>
<p dir="auto"><strong>JVM version</strong>: 1.8.0_25</p>
<p dir="auto"><strong>OS version</strong>: OSX 10.11.5</p>
<p dir="auto"><strong>Description of the problem including expected versus actual behavior</strong>:</p>
<p dir="auto"><strong>Steps to reproduce</strong>:</p>
<ol dir="auto">
<li>Define a nested object type in your mapping</li>
<li>Index some documents</li>
<li>Perform a nested query with a query_string on on of the field of the nested object using a wildcard</li>
</ol>
<p dir="auto">I am indexing the following document with a nested type locations:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="curl -X PUT 'http://localhost:9201/test_nested?pretty' -d '{
  &quot;settings&quot;: {
    &quot;index&quot;: {
      &quot;number_of_shards&quot;: 5,
      &quot;number_of_replicas&quot;: 1
    }
  },
  &quot;mappings&quot;: {
    &quot;loc&quot;: {
      &quot;properties&quot;: {
        &quot;id&quot;: {
          &quot;type&quot;: &quot;string&quot;,
          &quot;index&quot;: &quot;not_analyzed&quot;
        },
        &quot;locations&quot;: {
          &quot;type&quot;: &quot;nested&quot;,
          &quot;properties&quot;: {
            &quot;input&quot;: {
              &quot;type&quot;: &quot;string&quot;,
              &quot;index&quot;: &quot;not_analyzed&quot;
            },
            &quot;country_code&quot;: {
              &quot;type&quot;: &quot;string&quot;,
              &quot;index&quot;: &quot;not_analyzed&quot;
            }
          }
        }
      }
    }
  }
}'

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

curl -X PUT 'http://localhost:9201/test_nested/loc/location_2' -d '{
    id: &quot;location_2&quot;,
    &quot;locations&quot;: [
      {
        input: &quot;zzz&quot;,
        country_code: &quot;BR&quot;
      },
      {
        input: &quot;vvv&quot;,
        country_code: &quot;US&quot;
      }
    ]
}'"><pre class="notranslate"><code class="notranslate">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"
      }
    ]
}'
</code></pre></div>
<p dir="auto">When i try todo an extact match using query_string it works:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="curl -X POST 'http://localhost:9201/test_nested/_search' -d '
{
 &quot;query&quot;: {
       &quot;nested&quot;: {
           &quot;path&quot;: &quot;locations&quot;,
           &quot;query&quot;: {
               &quot;query_string&quot;: {
                   &quot;fields&quot;: [
                       &quot;locations.country_code&quot;
                   ],
                   &quot;query&quot;: &quot;BE&quot;
               }
           }
       }
   }
}
'

RESULT:

{&quot;took&quot;:1,&quot;timed_out&quot;:false,&quot;_shards&quot;:{&quot;total&quot;:5,&quot;successful&quot;:5,&quot;failed&quot;:0},&quot;hits&quot;:{&quot;total&quot;:1,&quot;max_score&quot;:2.098612,&quot;hits&quot;:[{&quot;_index&quot;:&quot;test_nested&quot;,&quot;_type&quot;:&quot;loc&quot;,&quot;_id&quot;:&quot;location_1&quot;,&quot;_score&quot;:2.098612,&quot;_source&quot;:{
    id: &quot;location_1&quot;,
    &quot;locations&quot;: [
      {
        input: &quot;xxx&quot;,
        country_code: &quot;BE&quot;
      },
      {
        input: &quot;yyy&quot;,
        country_code: &quot;NL&quot;
      }"><pre class="notranslate"><code class="notranslate">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"
      }
</code></pre></div>
<p dir="auto">When i try todo a wildcard it does not return anything:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="curl -X POST 'http://localhost:9201/test_nested/_search' -d '
{
 &quot;query&quot;: {
       &quot;nested&quot;: {
           &quot;path&quot;: &quot;locations&quot;,
           &quot;query&quot;: {
               &quot;query_string&quot;: {
                   &quot;fields&quot;: [
                       &quot;locations.country_code&quot;
                   ],
                   &quot;query&quot;: &quot;B*&quot;
               }
           }
       }
   }
}
'

RESULT:

{&quot;took&quot;:1,&quot;timed_out&quot;:false,&quot;_shards&quot;:{&quot;total&quot;:5,&quot;successful&quot;:5,&quot;failed&quot;:0},&quot;hits&quot;:{&quot;total&quot;:0,&quot;max_score&quot;:null,&quot;hits&quot;:[]}}"><pre class="notranslate"><code class="notranslate">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":[]}}
</code></pre></div>
<p dir="auto">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:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="curl -X POST 'http://localhost:9201/test_nested/_search' -d '
{
   &quot;query&quot;: {
       &quot;query_string&quot;: {
           &quot;fields&quot;: [
               &quot;id&quot;
           ],
           &quot;query&quot;: &quot;location_*&quot;
       }
   }
}
'

RESULT:

{&quot;took&quot;:1,&quot;timed_out&quot;:false,&quot;_shards&quot;:{&quot;total&quot;:5,&quot;successful&quot;:5,&quot;failed&quot;:0},&quot;hits&quot;:{&quot;total&quot;:2,&quot;max_score&quot;:1.0,&quot;hits&quot;:[{&quot;_index&quot;:&quot;test_nested&quot;,&quot;_type&quot;:&quot;loc&quot;,&quot;_id&quot;:&quot;location_1&quot;,&quot;_score&quot;:1.0,&quot;_source&quot;:{
    id: &quot;location_1&quot;,
    &quot;locations&quot;: [
      {
        input: &quot;xxx&quot;,
        country_code: &quot;BE&quot;
      },
      {
        input: &quot;yyy&quot;,
        country_code: &quot;NL&quot;
      }
    ]
}},{&quot;_index&quot;:&quot;test_nested&quot;,&quot;_type&quot;:&quot;loc&quot;,&quot;_id&quot;:&quot;location_2&quot;,&quot;_score&quot;:1.0,&quot;_source&quot;:{
    id: &quot;location_2&quot;,
    &quot;locations&quot;: [
      {
        input: &quot;zzz&quot;,
        country_code: &quot;BR&quot;
      },
      {
        input: &quot;vvv&quot;,
        country_code: &quot;US&quot;
      }
    ]
}}]}}
"><pre class="notranslate"><code class="notranslate">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"
      }
    ]
}}]}}

</code></pre></div>
<p dir="auto">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.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="curl -X POST 'http://localhost:9201/test_nested/_search' -d '
{
 &quot;query&quot;: {
       &quot;nested&quot;: {
           &quot;path&quot;: &quot;locations&quot;,
           &quot;query&quot;: {
               &quot;wildcard&quot;: {
                   &quot;locations.country_code&quot;: &quot;B*&quot;
               }
           }
       }
   }
}
'

{&quot;took&quot;:1,&quot;timed_out&quot;:false,&quot;_shards&quot;:{&quot;total&quot;:5,&quot;successful&quot;:5,&quot;failed&quot;:0},&quot;hits&quot;:{&quot;total&quot;:2,&quot;max_score&quot;:1.0,&quot;hits&quot;:[{&quot;_index&quot;:&quot;test_nested&quot;,&quot;_type&quot;:&quot;loc&quot;,&quot;_id&quot;:&quot;location_1&quot;,&quot;_score&quot;:1.0,&quot;_source&quot;:{
    id: &quot;location_1&quot;,
    &quot;locations&quot;: [
      {
        input: &quot;xxx&quot;,
        country_code: &quot;BE&quot;
      },
      {
        input: &quot;yyy&quot;,
        country_code: &quot;NL&quot;
      }
    ]
}},{&quot;_index&quot;:&quot;test_nested&quot;,&quot;_type&quot;:&quot;loc&quot;,&quot;_id&quot;:&quot;location_2&quot;,&quot;_score&quot;:1.0,&quot;_source&quot;:{
    id: &quot;location_2&quot;,
    &quot;locations&quot;: [
      {
        input: &quot;zzz&quot;,
        country_code: &quot;BR&quot;
      },
      {
        input: &quot;vvv&quot;,
        country_code: &quot;US&quot;
      }
    ]
}}]}}"><pre class="notranslate"><code class="notranslate">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"
      }
    ]
}}]}}
</code></pre></div>
<p dir="auto">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.</p>
<p dir="auto">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.</p>
<p dir="auto">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 :)</p>
<p dir="auto">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.</p>
<p dir="auto">Sorry for the long explanation.</p>
<p dir="auto">Compare:</p>
<ul dir="auto">
<li><a href="http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/analysis/common/src/java/org/apache/lucene/analysis/core/LowerCaseFilterFactory.java?view=markup" rel="nofollow">http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/analysis/common/src/java/org/apache/lucene/analysis/core/LowerCaseFilterFactory.java?view=markup</a></li>
<li><a href="http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/analysis/common/src/java/org/apache/lucene/analysis/en/PorterStemFilterFactory.java?view=markup" rel="nofollow">http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/analysis/common/src/java/org/apache/lucene/analysis/en/PorterStemFilterFactory.java?view=markup</a></li>
</ul>