Miss any of our Open RFC calls?Watch the recordings here! »

trailpack-elasticsearch

1.0.1 • Public • Published

trailpack-elasticsearch

📦 Elasticsearch Trailpack https://www.elastic.co/products/elasticsearch

Gitter NPM version Build status Dependency Status Code Climate

Provides a simple integration with elasticseach

Usage

Configure

// config/main.js
 
module.exports = {
 
  // ...
  packs: [
    require('trailpack-elasticsearch')
  ]  
}

Configure connection

Configuration file for Elasticsearch trailpack is: config/elasticsearch.js Otherwise you could use config/env/{env}.js files with elasticsearch property

 
// config/elasticsearch.js
 
module.exports = {
 
  connection: {
    // List of hosts for elastic cluster
    // hosts: [],
 
    // One elastic instance host
    host: 'localhost:9200',
    // Log level
    log: 'trace'
  },
 
  // Will validate if elastic connection is alive on Trails app start
  validateConnection: true
}

Using Elasticsearch API

This trailpack creates an app propertry with elasticseach client. app.elasticClient So you could use it whatever you want

// api/controller/SomeController.js
const Controller = require('trails-controller')
 
module.exports = class SomeController extends Controller {
 
  someAction (request, reply) {
    // Perform an action
    this.app.elasticClient
      .search({
        q: 'something'
      })
      .then(function (body) {
        const hits = body.hits.hits;
      }, function (error) {
        console.trace(error.message);
      })
  }
}

More information about Elasticsearch client could be found here: https://github.com/elastic/elasticsearch-js

Contributing

We love contributions! Please check out our Contributor's Guide for more information on how our projects are organized and how to get started.

License

MIT

Install

npm i trailpack-elasticsearch

DownloadsWeekly Downloads

0

Version

1.0.1

License

MIT

Last publish

Collaborators

  • avatar