Skip to content

Elasticsearch

The Elasticsearch data provider allows ChartFactor to interact with Elasticsearch through its HTTP API. Internally, it takes advantage of the Elasticsearch JavaScript API, elasticsearch.js, to perform all aggregation requests.

The Elasticsearch data provider supports Elasticsearch versions 5.x and 6.0.

First, we include the library in the main html of our app:

1
 <script src="./CFT-elasticsearch-provider.min.js"></script>

The Provider JSON object requires the url parameter in addition to name and provider parameters. Example:

1
2
3
4
5
var providers = [{
    name:'ElasticSearch',
    provider:'elasticsearch',
    url:'https://chartfactor.com:9200'
}]

Then, use the setProviders() method of ChartFactor to set your data provider definitions. Example:

1
cf.setProviders(providers);

Wildcard Source Name Support

The Elasticsearch data provider supports wildcard source names. For example, in a logging use case, a typical index name is made of a string prefix and the date in YYYY.MM.DD format. In this situation, you can create visualizations using a source that includes all indexes for every day in May using a pattern like logstash-2015.05*. Example:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
// define providers
var providers = [{
    name:'ElasticSearch',
    provider:'elasticsearch',
    url:'https://chartfactor.com:9200'
}]

cf.setProviders(providers);

// obtain datas source
var ticketSales = cf.provider('ElasticSearch').source('logstash-2015.05*');

Supported Aggregations Out-Of-The-Box

SUM

1
    var metric = cf.Metric("amount","sum");

AVG

1
    var metric = cf.Metric("amount","avg");

MIN

1
    var metric = cf.Metric("amount","min");

MAX

1
    var metric = cf.Metric("amount","max");

COUNT DISTINCT

1
    var metric = cf.Metric("my_attribute","unique");

Dependencies

  • elasticsearch.js 14.0.0