<p dir="auto">The include/exclude clause used in aggregations like <em>terms</em> agg uses regex syntax to identify terms.<br>
While this offers a lot of flexibility for matching, the list of terms supplied by a user is sometimes a fixed set of raw values and it is:<br>
a) inconvenient for the user to have to escape these strings into "legal" regex patterns and<br>
b) inefficient to parse and interpret these as regex patterns when a simple hashset would suffice</p>
<p dir="auto">The proposed change is the addition of a "values" array to both <em>include</em> and <em>exclude</em>  clauses:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&quot;terms&quot; : {
    &quot;field&quot; : &quot;domains.raw&quot;, 
    &quot;include&quot; : {
        &quot;values&quot;:  [ &quot;http://www.foo.com&quot;, &quot;http://www.bar.com&quot;]
    }
}"><pre class="notranslate"><code class="notranslate">"terms" : {
    "field" : "domains.raw", 
    "include" : {
        "values":  [ "http://www.foo.com", "http://www.bar.com"]
    }
}
</code></pre></div>
<p dir="auto">This can be used in conjunction or instead of the existing "pattern" clause in a search. If an include or exclude statement contains a mix of regex ("pattern") and exact ("values") clauses then this would be a logical OR - a match on the regex clause OR the exact value clause would constitute a match.</p>
<p dir="auto"><a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/clintongormley/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/clintongormley">@clintongormley</a> you may have some input on this?</p>
<p dir="auto">In facets, we can filter a Terms Facet using an <a href="http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-facets-terms-facet.html#_excluding_terms" rel="nofollow">array of values</a>:</p>
<div class="highlight highlight-source-json notranslate position-relative overflow-auto" dir="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;exclude&quot; : [&quot;term1&quot;, &quot;term2&quot;]
            }
        }
    }
}"><pre class="notranslate">{
    <span class="pl-ent">"query"</span> : {
        <span class="pl-ent">"match_all"</span> : { }
    },
    <span class="pl-ent">"facets"</span> : {
        <span class="pl-ent">"tag"</span> : {
            <span class="pl-ent">"terms"</span> : {
                <span class="pl-ent">"field"</span> : <span class="pl-s"><span class="pl-pds">"</span>tag<span class="pl-pds">"</span></span>,
                <span class="pl-ent">"exclude"</span> : [<span class="pl-s"><span class="pl-pds">"</span>term1<span class="pl-pds">"</span></span>, <span class="pl-s"><span class="pl-pds">"</span>term2<span class="pl-pds">"</span></span>]
            }
        }
    }
}</pre></div>
<p dir="auto">In aggs, we can't use the same syntax anymore as <a href="https://github.com/elasticsearch/elasticsearch/blob/1.2/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/support/IncludeExclude.java#L141-155">IncludeExclude</a> does not support arrays.</p>
<p dir="auto">Same apply for include.</p>
<p dir="auto">We can probably use <code class="notranslate">|</code> character to separate terms but it could be handy to be able to specify directly an array of terms.</p>
<p dir="auto">cc <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/jpountz/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/jpountz">@jpountz</a></p>