@cargatser/es_helper

Elasticsearch little helper for most common operations.

Usage no npm install needed!

<script type="module">
  import cargatserEsHelper from 'https://cdn.skypack.dev/@cargatser/es_helper';
</script>

README

ES_Helper

Elasticsearch little helper for most common operations.


Requirements

You will only need Node.js and @elastic/elasticsearch

Install

$ npm i es_helper

Configuration

INDEX_NAME, HOST and PORT are const variable inside es_helper.js

Default agg_size is 100

Example

$ var es_helper = require('es_helper')
$
$ // to get all buckets by field name
$ es_helper.getEsBucketsByFields(['FIELD_NAME', 'ANOTHER_FIELD_NAME'], 10, function(err, res) {
$
$ var aggResults = res.body.aggregations;
$
$ for (var aggTypeRes in aggResults) {
$
$	var singleAggBuckets = aggResults[aggTypeRes].buckets; // array
$
$	console.log("Results: ", JSON.stringify(singleAggBuckets, null, 4))
$ }

})

List of available commands

// to get list of aggs based by field(s)

  • getEsBucketsByFields(array, size, callback)