2013-09-17 09:01:35 -07:00

elasticsearch.js

Official low-level client for Elasticsearch.

This project's goal it to give the JavaScript community a solif foundation for all Elasticsearch-related code. It features a complete API, provides a module for use in Node.js as well as several different builds for use in the browser. We have tried to be opinion-free and very plugable.

Features

  • One-to-one mapping with REST API and other language clients
  • Generalized, pluggable architecture. See replacing core components
  • Configurable, automatic discovery of cluster nodes
  • Persistent, Keep-Alive connections
  • Load balancing (with pluggable selection strategy) across all availible nodes. Defaults to round-robin
  • Pluggable connection pools to offer different connection strategies

Node and the browser

elasticsearch.js works great in node, as well as the browser (many thanks to browserify).

  • Node: Build Status
  • Browsers:
  • testling results for browser clients

Install in Node

npm install --save elasticsearch

Browser Builds

Download one of these builds:

API

To maintain consistency across all the low-level clients (Ruby, Python, etc), clients accept all of their parameters via a single object, along with a single callback.

create the client

var es = new elasticsearch.Client({
  hosts: [
    'localhost:9200'
  ],
  log: 'trace',
  sniffOnStart: true
});

call an endpoint

es.cluster.nodeInfo({
  clear: true,
  jvm: true,
  os: ture
}, function (err, resp, status) {
    // do your thing
})

skip the callback to get a promise back

es.search({
  q: 'pants'
}).then(function (resp) {
  // use resp.body and resp.status
}, function (err) {
  // freak out!
})

abort a request

var req = es.search({
  q: 'robots'
}, function (err, body, status) {
  clearTimeout(timeout);
  // do something
});

var timeout = setTimeout(function () {
  req.abort();
}, 200);

or just use the timeout param

es.search({
  q: '*',
  timeout: 200
}).then(function (resp) {
  // Iterate all the hits
})
Description
Official Elasticsearch client library for Node.js
Readme Apache-2.0 36 MiB
Languages
TypeScript 96.7%
JavaScript 2.6%
Shell 0.7%