title: Elasticsearch NodeJS search : How to retrieve results from response
body: <p>I am trying to search in Elasticsearch using node js. Here is my script</p>
  
  <pre><code>var elasticsearch = require('elasticsearch');
  var client = elasticsearch.Client({
    host: 'localhost:9200',
    log: 'trace'
  });
  
  client.ping({
    // ping usually has a 3000ms timeout
    requestTimeout: Infinity,
  
    // undocumented params are appended to the query string
    hello: "elasticsearch!"
  }, function (error) {
    if (error) {
      console.trace('elasticsearch cluster is down!');
    } else {
      console.log('All is well');
      getmeres(client);
  
    }
  });
  
  function getmeres(client)
  {
  client.search({
        index: 'researchtest',
        body: {
  
                "aggs": {
                  "docs": {
                    "terms": {
                      "field": "DocumentID",
                      "size": 0
                    }
                  }
                }
  
        }
      }, function (error, response) {
          if (error) {
              console.trace('Search query failed');
            } else {
              console.log('All is well');
              d=response;//console.log(response);
              showdocs(d)
            }
      });
  }
  
  function showdocs(d){
  console.log(d["hits"]);}
  </code></pre>
  
  <p>i get</p>
  
  <pre><code>All is well
  { total: 92,
    max_score: 1,
    hits: 
     [ { _index: 'researchtest',
         _type: 'test',
         _id: 'AVLC2axzrLgN-DZLLsmp',
         _score: 1,
         _source: [Object] },
       { _index: 'researchtest',
         _type: 'test',
         _id: 'AVLC2izQrLgN-DZLLsnw',
         _score: 1,
         _source: [Object] },
       { _index: 'researchtest',
         _type: 'test',
         _id: 'AVLC2EEnrLgN-DZLLsjj',
         _score: 1,
         _source: [Object] },
       { _index: 'researchtest',
         _type: 'test',
         _id: 'AVLC2F7MrLgN-DZLLsj6',
         _score: 1,
         _source: [Object] },
       { _index: 'researchtest',
         _type: 'test',
         _id: 'AVLC2nhDrLgN-DZLLsol',
         _score: 1,
         _source: [Object] },
       { _index: 'researchtest',
         _type: 'test',
         _id: 'AVLC2pMUrLgN-DZLLsox',
         _score: 1,
         _source: [Object] },
       { _index: 'researchtest',
         _type: 'test',
         _id: 'AVLC2mTMrLgN-DZLLsoL',
         _score: 1,
         _source: [Object] },
       { _index: 'researchtest',
         _type: 'test',
         _id: 'AVLC2rDZrLgN-DZLLspS',
         _score: 1,
         _source: [Object] },
       { _index: 'researchtest',
         _type: 'test',
         _id: 'AVLC2t5ErLgN-DZLLsp8',
         _score: 1,
         _source: [Object] },
       { _index: 'researchtest',
         _type: 'test',
         _id: 'AVLC2dVHrLgN-DZLLsnA',
         _score: 1,
         _source: [Object] } ] }
  </code></pre>
  
  <p>but i dont see the actual values that i want here. how do i get values from the response? In the console i also see </p>
  
  <pre><code>"aggregations": {
        "docs": {
          "doc_count_error_upper_bound": 0,
          "sum_other_doc_count": 0,
          "buckets": [
            {
              "key": "2235",
              "doc_count": 2
            },
            {
              "key": "12312",
              "doc_count": 2
            },
            {
              "key": "4565",
              "doc_count": 2
            },
            {
              "key": "7809780",
              "doc_count": 2
            },
            {
              "key": "8678",
              "doc_count": 2
            },
  </code></pre>
  
  <p>and it goes on to list all of the matched results</p>
  
  <ol>
  <li><p>I only want the unique values, how should i specify the aggregation for that?</p></li>
  <li><p>How do i extract the actual values or <code>keys</code> in this case, from the result of the above query?</p></li>
  </ol>
  
  <p><strong>Edit</strong></p>
  
  <p>so i kind of figured it out. i am able to access by</p>
  
  <pre><code>function showdocs(d){
      da=d.hits.hits
  
      for (i=0;i&lt;da.length;i++)
          {
  console.log(da[i]["_source"]["DocumentID"]);}}
  </code></pre>
  
  <p>but this only gives me 10 results back! I know for sure that i have 50 distinct values in that field</p>