<commit_before># appbase-js

Appbase.io is a data streams library for Node.JS and Javascript (browser build is in the [browser/](https://github.com/appbaseio/appbase-js/tree/master/browser) directory); compatible with [elasticsearch.js](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/index.html).

## Quick Example

Working code snippets where each step builds on the previous ones.

#### Step 1: Add some data into the app (uses elasticsearch.js)
```js
// app and authentication configurations 
const HOSTNAME = "scalr.api.appbase.io"
const APPNAME = "createnewtestapp01"
const USERNAME = "RIvfxo1u1"
const PASSWORD = "<PASSWORD>"

// Add data into our ES "app index"
var Appbase = require('appbase-js')
var appbase = new Appbase({
		url: 'https://'+USERNAME+":"+PASSWORD+"@"+HOSTNAME,
		appname: APPNAME
	});
appbase.index({
    type: "product",
    id: "1",
    body: {
        name: 'A green door',
        price: 12.50,
        tags: ['home', 'green'],
        stores: ['Walmart', 'Target']
    }
}).on('data', function(res) {
    console.log(res);
}).on('error', function(err) {
	console.log(err);
});
```

#### Step 2: Stream the Document Updates

```js
appbase.streamDocument({
      type: 'product',
      id: '1'
}).on('data', function(res) {
      // 'data' handler is triggered every time there is a document update.
      console.log(res);
}).on('error', function(err) {
      console.log("caught a stream error", err);
})
```

##### Console Output

```js
{ _index: 'app`248',
  _type: 'product',
  _id: '1',
  _version: 4,
  found: true,
  _source: 
   { name: 'A green door',
     price: 12.5,
     tags: [ 'home', 'green' ],
     stores: [ 'Walmart', 'Target' ] } }
```

streamDocument() returns a ``stream.Readable`` object, which can be conveniently listened via the 'on("data")' event listener. Check out the [stream_document_test.js](https://github.com/appbaseio/appbase-js/blob/master/test/stream_document_test.js) where we make an update to the document and see any further updates to it via the 'data' event. 

#### Step 3: Streaming Queries

While streaming documents is straightforward, streaming queries touch the entire breadth of [ElasticSearch Query DSL](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl.html) - boolean, regex, geo, fuzzy to name a few. Let's stream the results of a simple **``match_all``** query on the ``product`` type:

```js
appbae.streamSearch({
	type: 'product',
	body: {
		query: {
			match_all: {}
		}
	}
}).on('data', function(res, err) {
	console.log(res);
}).on('error', function(err) {
	console.log("caught a stream error", err);
})
```

##### Console Output

```js
{ took: 1,
  timed_out: false,
  _shards: { total: 1, successful: 1, failed: 0 },
  hits: 
   { total: 4,
     max_score: 1,
     hits: [ [Object], [Object], [Object], [Object] ] } }
```<commit_msg>Typo removed - "appbae"->"appbase"<commit_after># appbase-js

Appbase.io is a data streams library for Node.JS and Javascript (browser build is in the [browser/](https://github.com/appbaseio/appbase-js/tree/master/browser) directory); compatible with [elasticsearch.js](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/index.html).

## Quick Example

Working code snippets where each step builds on the previous ones.

#### Step 1: Add some data into the app (uses elasticsearch.js)
```js
// app and authentication configurations 
const HOSTNAME = "scalr.api.appbase.io"
const APPNAME = "createnewtestapp01"
const USERNAME = "RIvfxo1u1"
const PASSWORD = "<PASSWORD>"

// Add data into our ES "app index"
var Appbase = require('appbase-js')
var appbase = new Appbase({
		url: 'https://'+USERNAME+":"+PASSWORD+"@"+HOSTNAME,
		appname: APPNAME
	});
appbase.index({
    type: "product",
    id: "1",
    body: {
        name: 'A green door',
        price: 12.50,
        tags: ['home', 'green'],
        stores: ['Walmart', 'Target']
    }
}).on('data', function(res) {
    console.log(res);
}).on('error', function(err) {
	console.log(err);
});
```

#### Step 2: Stream the Document Updates

```js
appbase.streamDocument({
      type: 'product',
      id: '1'
}).on('data', function(res) {
      // 'data' handler is triggered every time there is a document update.
      console.log(res);
}).on('error', function(err) {
      console.log("caught a stream error", err);
})
```

##### Console Output

```js
{ _index: 'app`248',
  _type: 'product',
  _id: '1',
  _version: 4,
  found: true,
  _source: 
   { name: 'A green door',
     price: 12.5,
     tags: [ 'home', 'green' ],
     stores: [ 'Walmart', 'Target' ] } }
```

streamDocument() returns a ``stream.Readable`` object, which can be conveniently listened via the 'on("data")' event listener. Check out the [stream_document_test.js](https://github.com/appbaseio/appbase-js/blob/master/test/stream_document_test.js) where we make an update to the document and see any further updates to it via the 'data' event. 

#### Step 3: Streaming Queries

While streaming documents is straightforward, streaming queries touch the entire breadth of [ElasticSearch Query DSL](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl.html) - boolean, regex, geo, fuzzy to name a few. Let's stream the results of a simple **``match_all``** query on the ``product`` type:

```js
appbase.streamSearch({
	type: 'product',
	body: {
		query: {
			match_all: {}
		}
	}
}).on('data', function(res, err) {
	console.log(res);
}).on('error', function(err) {
	console.log("caught a stream error", err);
})
```

##### Console Output

```js
{ took: 1,
  timed_out: false,
  _shards: { total: 1, successful: 1, failed: 0 },
  hits: 
   { total: 4,
     max_score: 1,
     hits: [ [Object], [Object], [Object], [Object] ] } }
```
{'fraction_non_alphanumeric': 0.16776315789473684, 'fraction_numerical': 0.009349030470914127, 'mean_word_length': 3.862794612794613, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 10, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6085933', 'n_tokens_mistral': 2001, 'n_tokens_neox': 1896, 'n_words': 568}