title: How to limit elasticsearch to a list of documents each identified by a unique keyword
body: <p>I have an elasticsearch document repository with ~15M documents.</p>
  
  <p>Each document has an unique 11-char string field (comes from a mongo DB) that is unique to the document. This field is indexed as <code>keyword</code>.</p>
  
  <p>I'm using C#.</p>
  
  <p>When I run a search, I want to be able to limit the search to a set of documents that I specify (via some list of the unique field ids).</p>
  
  <p>My query text uses <code>bool</code> with <code>must</code> to supply a <code>filter</code> for the unique identifiers and additional clauses to actually search the documents. See example below.</p>
  
  <p>To search a large number of documents, I generate multiple query strings and run them concurrently. Each query handles up to 64K unique ids (determined by the limit on <code>terms</code>).</p>
  
  <p>In this case, I have 262,144 documents to search (list comes, at run time, from a separate mongo DB query). So my code generates 4 query strings (see example below).</p>
  
  <p>I run them concurrently.</p>
  
  <p>Unfortunately, this search takes over 22 seconds to complete.</p>
  
  <p>When I run the same search but drop the <code>terms</code> node (so it searches all the documents), a single such query completes the search in 1.8 seconds.</p>
  
  <p>An incredible difference.</p>
  
  <p>So my question: <strong>Is there an efficient way to specify which documents are to be searched (when each document has a unique self-identifying keyword field)?</strong></p>
  
  <p>I want to be able to specify up to a few 100K of such unique ids.</p>
  
  <p>Here's an example of my search specifying unique document identifiers:</p>
  
  <pre><code>{
      "_source" : "talentId",
      "from" : 0,
      "size" : 10000,
      "query" : {
          "bool" : {
              "must" : [
                  {
                      "bool" : {
                          "must" : [  {  "match_phrase" : { "freeText" : "java" } },
                                      {  "match_phrase" : { "freeText" : "unix" } },
                                      {  "match_phrase" : { "freeText" : "c#" } },
                                      {  "match_phrase" : { "freeText" : "cnn" } } ]
                      }
                  },
                  {
                      "bool" : {
                          "filter" : {
                              "bool" : {
                                  "should" : [
                                      {
                                          "terms" : {
                                              "talentId" : [ "goGSXMWE1Qg",  "GvTDYS6F1Qg",
                                                             "-qa_N-aC1Qg", "iu299LCC1Qg",
                                                             "0p7SpteI1Qg",  ... 4,995 more ...  ]
                                          }
                                      }
                                  ]
                              }
                          }
                      }
                  }
              ]
          }
      }
  } 
  
  </code></pre>