Skip to content

Commit

Permalink
Add installation instruction & syntax highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
vespakoen committed Oct 9, 2015
1 parent 44cc4df commit 13a802d
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@ It is expected to provide the Elasticsearch reponse's body as a JSON.

See the examples and tests with the official Elasticsearch-js client.

# Installation

```shell
npm install --save elasticsearch-streams
```

# Examples:

## Stream random records into Elasticsearch
```
```js
var WritableBulk = require('elasticsearch-streams').WritableBulk;
var client = new require('elasticsearch').Client();

Expand All @@ -38,14 +44,14 @@ https://github.com/joyent/node/issues/5315#issuecomment-16670354

For example to close the ES client as soon as we are done:

```
```js
ws.on('close', function () {
client.close();
});
```

## Stream search results from Elasticsearch
```
```js
var ReadableSearch = require('elasticsearch-streams').ReadableSearch;
var client = new require('elasticsearch').Client();

Expand All @@ -72,7 +78,7 @@ rs.pipe(ws).on('close', done);

If we want to start the stream at an offset and define a limit:

```
```js
var offset = 7;
var limit = 21;
var page = 12;
Expand All @@ -90,7 +96,7 @@ var searchExec = function searchExec(from, callback) {
```

## Stream scroll/scan results from Elasticsearch
```
```js
var scrollExec = function scrollExec(from, callback) {
if (this.scroll_id) {
return client.scroll({
Expand All @@ -116,7 +122,7 @@ rs = new ReadableSearch(scrollExec);
```

## Stream IDs into Elasticsearch multi-get and get documents out.
```
```js
var mgetExec = function(docs, callback) {
client.mget({
index: 'myindex',
Expand Down

0 comments on commit 13a802d

Please sign in to comment.