rx-elasticsearch
Version:
RxJS Observables for the Elasticsearch client
76 lines (64 loc) • 1.74 kB
Markdown
RxJS Observables for the Elasticsearch javascript client
Install with npm
` npm install rx-elasticsearch --save`
Wrap existing Elasticsearch client
```js
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
```js
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.
```js
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.
```js
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
```js
var RxClient = require('rx-elasticsearch').default;
```