Fastify plugin for elastic search
Switch branches/tags
Nothing to show
Clone or download
Latest commit e14cdda Nov 13, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore ping cluster before make plugin ready, refactor some code Mar 30, 2018
.travis.yml Update to node 10 in .travis.yml (#10) Apr 29, 2018
LICENSE Initial commit Mar 2, 2018 Fix wrong require in example Mar 30, 2018
index.js Updated required fastify version Apr 3, 2018
package.json Bumped v0.4.0 Nov 13, 2018
test.js better errors Mar 30, 2018


js-standard-style Build Status Greenkeeper badge

Fastify plugin for elastic search for sharing the same ES client in every part of your server.

Under the hood the official elasticsearch module is used.

Unless you give the client to this plugin, this module will pass all options to the ES Client constructor.

NB: this fastify plugin always close the elasticsearch client on server shutdown


npm i fastify-elasticsearch --save


Add it to your project with register and you are done!

const fastify = require('fastify')()

fastify.register(require('fastify-elasticsearch'), {
  host: '',
  port: 9200

fastify.get('/user/:id', function (req, reply) {
    index: 'myindex',
    type: 'user',
  }, function (err, response) {
    if (err) return reply.send(err)


fastify.listen(3000, err => {
  if (err) throw err

You may also supply a pre-configured instance of elasticsearch.Client:

const elasticsearch = require('elasticsearch')

const client = new elasticsearch.Client({ host: '', port: 9200 })
const fastify = require('fastify')()

fastify.register(require('fastify-elasticsearch'), { client: client })
  .register(function (fastify, opts, next) {
    const elasticsearch = fastify.elasticsearch
    // ...
    // ...
    // ...


Licensed under MIT.