title: ElasticSearch 5 - Migrating "missing" filter
body: <p>In ElasticSearch 1 and 2.x there was a "missing" filter which was used in the app we're currently migrating to 5.</p>
  
  <p>The "missing" filter was used to create a selection like this:
   Return all results where price is missing or price > 100.</p>
  
  <p>In ES5, the missing filter does not exist anymore and the docs say it can be replaced with a combination of "must_not" and "exists", but in my case, I'm writing an "or" query and there is no "should_not" clause.</p>
  
  <p>Excerpt from the docs at <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-exists-query.html" rel="nofollow noreferrer">https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-exists-query.html</a>:</p>
  
  <blockquote>
    <p>missing query has been removed because it can be advantageously replaced by an exists query inside a must_not clause as follows:</p>
  </blockquote>
  
  <pre><code>GET /_search
  {
      "query": {
          "bool": {
              "must_not": {
                  "exists": {
                      "field": "user"
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>How would you go about migrating this in ES5?</p>
  
  <p>Thanks!</p>
  
  <p>UPDATE: This is the PHP / Elastica code that is used to build the query. Unfortunatly I don't have the query in JSON, as the app doesn't run at this time. The idea is simple though: I want all results where the "price" is missing or greater than 100.</p>
  
  <pre><code>$and = new \Elastica\Filter\BoolFilter();
  $and-&gt;addMust(new \Elastica\Filter\Term(array('highlights_ids' =&gt; $highlight-&gt;getId())));
  
  $or = new \Elastica\Filter\BoolOr();
  $or-&gt;addFilter(new \Elastica\Filter\Missing('price')); // if price is missing =&gt; show always
  $or-&gt;addFilter(new \Elastica\Filter\Range("price", array('from' =&gt; $minPrice)));
  $and-&gt;addMust($or);
  
  $filter = new \Elastica\Query\BoolQuery(null, $and);
  $query = new \Elastica\Query($filter);
  
  $query-&gt;setFields(array()); // No fields, we get them from the db
  $query-&gt;setSize($max);
  
  $result = $this-&gt;tripProvider-&gt;search($query);
  </code></pre>