📦 Elasticsearch Spool https://www.elastic.co/products/elasticsearch
Provides a simple integration with elasticsearch
###Configure
// config/main.ts
import { ElasticsearchSpool } from '@fabirx/spool-elasticsearch'
export const main = {
// ...
spools: [
ElasticsearchSpool
]
}
Configuration file for Elasticsearch spool is: config/elasticsearch.ts
Otherwise you could use config/env/{env}.ts
files with elasticsearch
property
// config/elasticsearch.ts
export const elasticsearch = {
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 Fabrix app start
validateConnection: true
}
This spool creates an app propertry with elasticseach client. app.elasticClient
So you could use it whatever you want
// api/controller/SomeController.ts
export 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: Elasticsearch-js