'use strict';
const q = require('q');

class ElasticService {
  constructor(client, index, type) {
    this.client = client;
    this.type = type || 'LogMessage';
    this.index = index || 'pgp-logs-index';
  }

  /**
   *
   */
  search() {
    let queryParams = {
      index: this.index,
    };
    if (this.type) {
      queryParams.type = this.type;
    }
    queryParams.body = {
      query: {
        match_all: {}
      }
    };

    return this.fullSearch(queryParams);
  }

  /**
   *
   */
  searchFields() {
    this.client.indices.getMapping().then((resp) => {
      return q(resp);
    }).catch((err) => {
      return q(err);
    });
  }

  /**
   * Makes a full search with the givem params in the elasticsearch.
   */
  fullSearch(query) {
    return this.client.search(query || {}).then((resp) => {
      return q(resp.hits.hits);
    }).catch((err) => {
      return q.reject(err);
    });
  }
}

module.exports = ElasticService;

@@ -375,24 +375,57 @@
 ms.body = %7B%0A
+      from: 0,%0A      size: 1000,%0A
       query:

add from to in elastic service