From 13a802d2419b3a300d347a932c0de1155820ca24 Mon Sep 17 00:00:00 2001 From: Koen Schmeets Date: Fri, 9 Oct 2015 07:22:36 +0200 Subject: [PATCH] Add installation instruction & syntax highlighting --- README.md | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index fabfc5a..83ad7e8 100644 --- a/README.md +++ b/README.md @@ -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(); @@ -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(); @@ -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; @@ -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({ @@ -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',