Simple & handy client for elasticsearch. It's just a wrapper around
http.request
with shortcuts for elasticsearch.
It implements all available functionality & even upcoming.
Be careful while 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 asynchronous...
Looking for easy indices and mappings management with zero-downtime migrations? Check out ruby version.
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 with:
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.
method
- http request methodindex
type
path
- last part for urlid
- same aspath
but with higher priorityquery
- query string for url. you can set routing params heredata
- request body
You can omit fields stored in defaults
request(params, [callback])
get()
, put()
, post()
, delete()
- just set the method
putMapping()
- put withpath = '_mapping'
search()
- post withpath = '_search'
index()
- ifid
field is set thenput
elsepost
es.setType()
# 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 = type:
fields:
field_one: type: 'string'
es.putMapping data: mapping
# PUT http://host::port/other_index/type/_mapping
# body is json of mapping
es.get index: 'one', type: 'two', id: 'three'
# GET http://host::port/one/two/three
see tests
BSD