Simple & handy client for elasticsearch
Last updated 7 years ago by printercu .
BSD · Repository · Original npm · Tarball · package.json
$ cnpm install elastics 
SYNC missed versions from official npm registry.


Simple & handy client for elasticsearch. It's just wrapper around http.request with shortcuts for elasticsearch.

It implements all available functionality & even upcoming.

Be careful wile using settings for default type & index: they are client's instance variables. So if you are going to have one client in an application you'd better set them explicitly in each call. JS is so asynchronus...


Elastics = require 'elastics'
es = new Elastics
  host:  hostname # default 'localhost'
  port:  port     # default 9200
  index: index    # default null
  type:  type     # default null

This params are stored in es.defaults. You can change them wi

  • setIndex(index, [type = null])
  • setType(type)

For the first time I've made all the methods adaptive to arguments. But then there have appeared to much significant arguments so I gave it up.

So all the methods take two args: object with parameters & callback. For now you can omit callback but not params.

params fields:

  • method - http request method
  • index
  • type
  • path - last part for url
  • id - same as path but with higher priority
  • query - query string for url. you can set routing params here
  • data - request body

You can omit fields stored in defaults

lowest level

request(params, [callback])

request-type level

get(), put(), post(), delete() - just set the method

highest level

  • putMapping() - put with path = '_mapping'
  • search() - post with path = '_search'
  • index() - if id field is set then put else post

few examples

# index:null, type: null

es.get {}
# GET http://host::port/

es.post {index: 'index'}
# POST http://host::port/index 

es.setIndex 'other_index', 'type
mapping =
      field_one: type: 'string'
es.putMapping {data: mapping}
# PUT http://host::port/other_index/type
# body is json of mapping

es.get {index: 'one', type: 'two', id: 'three'}
# GET http://host::port/one/two/three

see tests



Current Tags

  • 0.3.0                                ...           latest (7 years ago)

2 Versions

  • 0.3.0                                ...           7 years ago
  • 0.2.0                                ...           7 years ago
Maintainers (1)
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (1)
Dev Dependencies (2)
Dependents (1)

Copyright 2014 - 2016 © taobao.org |