mono-elasticsearch
v2.1.4
Published
ElasticSearch module for Mono
Downloads
3
Readme
ElasticSearch module for Mono
Installation
npm install --save mono-elasticsearch
Then, in your configuration file of your Mono application (example: conf/application.js
):
module.exports = {
mono: {
modules: ['mono-elasticsearch']
}
}
Configuration
Mono-elasticsearch will use the elasticsearch
property of your configuration (example: conf/development.js
):
module.exports = {
mono: {
elasticsearch: {
// See https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/configuration.html
host: 'localhost:9200'
}
}
}
Usage
In your modules files, you can access client
instance like this:
const { client } = require('mono-elasticsearch')
client.ping({
// ping usually has a 3000ms timeout
requestTimeout: 1000
}, function (error) {
if (error) {
console.trace('elasticsearch cluster is down!');
} else {
console.log('All is well');
}
});
Utils
const { SearchValidation, getSearchOptions } = require('mono-elasticsearch')
searchValidation: Object
: Joi object used for route validation inside MonogetSearchOptions(req.query): Object
: Method to transformreq.query
into a usable object for elasticsearchfind
The last 2 methods are useful to create easily listing routes with pagination restriction, best used in combination with [elasticsearch-utils search()] (https://github.com/terrajs/elasticsearch-utils#search).
You can see an example of how to use it in test/fixtures/utils/src/utils.routes.js
.