<p dir="auto">If I have an inner object that has the same name as a type, then queries for that inner object will fail.</p>
<p dir="auto">The workaround is to rename the type or the inner object, but the behaviour is confusing and misleading (and wrong).</p>
<p dir="auto">To reproduce, create a new index, type and document:<br>
curl -XPOST 'localhost:9200/test/flow/' -d '{<br>
"device": {<br>
"id": "dummy"<br>
}<br>
}'</p>
<p dir="auto">Querying for that document by device.id will work:<br>
curl 'localhost:9200/test/_search?pretty' -d '{<br>
"query":{<br>
"filtered": {<br>
"filter": {<br>
"term": {<br>
"device.id": "dummy"<br>
}<br>
}<br>
}<br>
}<br>
}'</p>
<p dir="auto">Add a type with the same name as the inner object, AND containing an inner object with that name as well:<br>
curl -XPOST 'localhost:9200/test/device/' -d '{<br>
"device": {<br>
"id": "foo"<br>
}<br>
}'</p>
<p dir="auto">Now querying for the original document by device.id will fail:<br>
{<br>
"took" : 0,<br>
"timed_out" : false,<br>
"_shards" : {<br>
"total" : 5,<br>
"successful" : 5,<br>
"failed" : 0<br>
},<br>
"hits" : {<br>
"total" : 0,<br>
"max_score" : null,<br>
"hits" : [ ]<br>
}<br>
}</p>
<p dir="auto">Removing the 'device' type will allow the original document to be queryable again:<br>
curl -XDELETE 'localhost:9200/test/device'</p>
<p dir="auto">As far as I understand it, fields are resolved on a <em>first found</em> basis. So given the following documents:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="PUT /index/foo/1
{
    &quot;count&quot;: 1,
    &quot;foo&quot;: {
        &quot;count&quot;: 1
    }
}

PUT /index/bar/2
{
    &quot;count&quot;: 1,
    &quot;foo&quot;: {
        &quot;count&quot;: 1
    }
}"><pre class="notranslate"><code class="notranslate">PUT /index/foo/1
{
    "count": 1,
    "foo": {
        "count": 1
    }
}

PUT /index/bar/2
{
    "count": 1,
    "foo": {
        "count": 1
    }
}
</code></pre></div>
<p dir="auto">.... the field <code class="notranslate">foo.count</code> could resolve to <code class="notranslate">foo.count</code>, <code class="notranslate">foo.foo.count</code>, or <code class="notranslate">bar.foo.count</code>, depending on which is found first.</p>
<p dir="auto">Field resolution should be unambiguous. Field names should be grouped by type and sorted in descending order by number of <code class="notranslate">.</code>. So the above mappings should result in:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="bar:
    foo.count
    count

foo:
   foo.count
   count"><pre class="notranslate"><code class="notranslate">bar:
    foo.count
    count

foo:
   foo.count
   count
</code></pre></div>
<p dir="auto">Then if no type is specified (or multiple types are specified), go through the groups in alphabetical order.</p>
<p dir="auto">This would result in the following resolutions:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="foo.foo.count   =&gt; (foo) foo.count
foo.count       =&gt; (foo) count
count           =&gt; (bar) count
*.foo.count     =&gt; (bar) foo.count
*.count         =&gt; (bar) count
*.*.count       =&gt; (bar) foo.count"><pre class="notranslate"><code class="notranslate">foo.foo.count   =&gt; (foo) foo.count
foo.count       =&gt; (foo) count
count           =&gt; (bar) count
*.foo.count     =&gt; (bar) foo.count
*.count         =&gt; (bar) count
*.*.count       =&gt; (bar) foo.count
</code></pre></div>