Elasticsearch query to find range overlap
<p>Let's say I have the following indexed document:</p>

<pre><code>{
    "field1": [400, 800]
}
</code></pre>

<p>I want to create a query using 2 search parameters (<code>min_val = 300</code> and <code>max_val = 500</code>) to select documents where these two ranges overlaps.</p>

<p>In my example, the above document should be selected, as we can see:</p>

<pre><code>300                    500
 [======================]
                   [=====================]
                  400                   800
</code></pre>

<p>What is the most efficient way to find documents that overlap two numeric ranges?
I can make it using multiple comparisons, and many <em>ands</em> and <em>ors</em>, but I'm looking for a simpler and efficient way to achieve this.</p>