<p dir="auto">Similar in scope to the current 'ignore_unmapped' (issue <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="2630819" data-permission-text="Title is private" data-url="https://github.com/elastic/elasticsearch/issues/1558" data-hovercard-type="issue" data-hovercard-url="/elastic/elasticsearch/issues/1558/hovercard" href="https://github.com/elastic/elasticsearch/issues/1558">#1558</a>) used for sorting search results, this parameter would prevent an exception from being generated when a given term is not mapped within an index during a faceted search.</p>
<p dir="auto">This would be most helpful when generating faceted results across multiple indexes and a certain term does not exist in a given index within the search. The results for the indexes where a term does exist would still be created.</p>
<p dir="auto">An example:<br>
indexA,indexB,indexC/blogs/_search</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="{
    &quot;query&quot; : {
        &quot;match_all&quot; : {  }
    },
    &quot;facets&quot; : {
        &quot;tag&quot; : {
            &quot;terms&quot; : {
                &quot;field&quot; : &quot;tag&quot;,
                &quot;size&quot; : 10,
                &quot;ignore_missing&quot;: true
            }
        }
    }
}"><pre class="notranslate"><code class="notranslate">{
    "query" : {
        "match_all" : {  }
    },
    "facets" : {
        "tag" : {
            "terms" : {
                "field" : "tag",
                "size" : 10,
                "ignore_missing": true
            }
        }
    }
}
</code></pre></div>
<p dir="auto">This should be applied across all facet queries: term, range, histogram, date histogram, statistical, etc.<br>
This ticket could be modified to apply the flag via the uri.</p>
<p dir="auto">An optional parameter on the facet, like sort's "ignore_unmapped" parameter would be great.</p>
<p dir="auto">Context : We use "dynamic_templates" in our index mapping and allow clients to search, sort, and "facet" on any field that is valid by the rules of the mapping.</p>
<p dir="auto">The problem arises when facets are run on fields that do not exist in the data, and thus are not "actually" in the mapping.</p>
<p dir="auto">Example : With a "dynamic_template" for "rating-*" fields, we can search, filter, and sort<br>
(with "ignore_unmapped" = true), against a "rating-Tuna" field, even though there are no<br>
documents in the index with that field.</p>
<p dir="auto">See Gist <a href="https://gist.github.com/4568689">https://gist.github.com/4568689</a> for a script that will quickly demonstrate the problem.</p>