IMPORTANT: elasticsearch.js has been replaced by the new Elasticsearch JavaScript client. We strongly advise you to migrate to the new client. To learn more, see the migration guide.
Client/API
editClient/API
editExtending or replacing the API that Elasticsearch.js provides is a simple as it should be in JS. To provide an entirely new API, just add it to the Client constructor’s api
property like so:
var myApi = { getDog: function () { ... } }; elasticsearch.Client.apis.mine = myApi; var client = new elasticsearch.Client({ apiVersion: 'mine' }); client.getDog( ... );
When the client is created, its prototype is set to the API version selected, and therefore you can access the client via the this
variable within your API methods. Make requests within your methods using this.transport.request(params, cb)
. For more information about the transport, see Transport.