rx-elasticsearch
v0.2.5
Published
RxJS Observables for the Elasticsearch client
Downloads
5
Maintainers
Readme
Rx-elasticsearch
RxJS Observables for the Elasticsearch javascript client
Install with npm
npm install rx-elasticsearch --save
Wrap existing Elasticsearch client
import RxClient from 'rx-elasticsearch';
import * as elasticsearch from 'elasticsearch';
let client = new elasticsearch.Client({
host: 'localhost:9200',
log: 'info'
});
let rxClient = new RxClient(client);
Initialization without Elasticsearch client
import RxClient from 'rx-elasticsearch';
let rxClient = RxClient.create({
host: 'localhost:9200',
log: 'info'
});
Usage is the same as the Elasticsearch client, but returns observables.
let params = {
index: 'yourIndex',
body: {
query: {
match_all: {}
}
}
};
rxClient
.search(params)
.subscribe(
(res) => console.log(res),
(e) => console.error(e),
() => console.log('done')
);
With the scroll function you no longer need to call search first. This library takes care of that and clears the scroll automagicly when the scroll is finished.
let params = {
index: 'yourIndex',
scroll: '1m',
size: 1000,
body: {
query: {
match_all: {}
}
}
};
rxClient
.scroll(params)
.subscribe(
(res) => console.log(res),
(e) => console.error(e),
() => console.log('done')
);
For older javascript versions
var RxClient = require('rx-elasticsearch').default;