title: Elastica: Best way to check if document with Id x exists?
body: <p>Using the PHP Elastica library, I'm wondering what is the best way to check whether a document with Id=1 exists?</p>
  
  <p>I was doing as follows:</p>
  
  <pre><code>$docPre = $elasticaType-&gt;getDocument(1);
  if ($docPre) {
      //do some stuff...
  } else {
      //do something else...
  }
  </code></pre>
  
  <p>However, the above code does not work because a NotFoundException is thrown by the getDocument() method if the document does not exist.</p>
  
  <p>Alternatively, I could do a type "search" using something like this:</p>
  
  <pre><code>$elasticaQueryString = new \Elastica\Query\QueryString();
  $elasticaQueryString-&gt;setParam('id', 1);
  $elasticaQuery = new \Elastica\Query();
  $elasticaQuery-&gt;setQuery($elasticaQueryString);
  $resultSet = $elasticaType-&gt;search($elasticaQuery);
  $count = $resultSet-&gt;count();
  if ($count &gt; 0) {
      //do some stuff...
  } else {
      //do something else...
  }
  </code></pre>
  
  <p>However, the above seems quite cumbersome... What's the better way?
  <a href="https://stackoverflow.com/questions/17059041/fancy-efficient-way-of-checking-if-a-document-exists-at-elasticsearch">This other question applies to ElasticSearch</a>, and one of the answers suggests my first approach (the equivalent to using getDocument). However, I do not want an Exception to be thrown, as it would be the case using Elastica...</p>