appbaseio/appbase-js

Name: appbase-js

Owner: appbase.io

Description: Appbase.io streaming client lib for Javascript

Created: 2015-07-27 07:01:17.0

Updated: 2018-05-01 09:43:30.0

Pushed: 2018-04-23 07:35:29.0

Homepage:

Size: 3134

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Build Status Image

appbase-js

Appbase.io is a data streams library for Node.JS and Javascript (browser UMD build is in the dist/ directory); compatible with elasticsearch.js.

An up-to-date documentation for Node.JS API is available at http://docs.appbase.io/javascript/quickstart.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)
pp and authentication configurations 
t HOST_URL = "https://scalr.api.appbase.io"
t APPNAME = "createnewtestapp01"
t CREDENTIALS = "RIvfxo1u1:dee8ee52-8b75-4b5b-be4f-9df3c364f59f"

dd data into our ES "app index"
Appbase = require("appbase-js")
appbase = new Appbase({
l: HOST_URL,
p: APPNAME,
edentials: CREDENTIALS

ase.index({
pe: "product",
: "1",
dy: {
name: "A green door",
price: 12.50,
tags: ["home", "green"],
stores: ["Walmart", "Target"]

n("data", function(res) {
nsole.log(res);
n("error", function(err) {
nsole.log(err);

Step 2: Read the data stream from a particular DB location

Returns continous updates on a JSON document from a particular type.

ase.getStream({
pe: "product",
: "1"
n("data", function(res) {
 "data" handler is triggered every time there is a **new** document update.
nsole.log(res);
n("error", function(err) {
nsole.log("caught a stream error", err);

Note: Existing document value is returned via get() method.

Console Output

ndex: "app`248",
ype: "product",
d: "1",
ersion: 4,
und: true,
ource: { 
name: "A green door",
price: 12.5,
tags: [ "home", "green" ],
stores: [ "Walmart", "Target" ] 


getStream() returns a stream.Readable object, which can be conveniently listened via the on("data") event listener. Check out the 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: Apply queries on data streams

Get continuous results by searching across the database streams. A query can be written using the ElasticSearch Query DSL - which supports composing boolean, regex, geo, fuzzy, range queries. Let's stream the results of a simple match_all query on the product type:

ase.searchStream({
pe: "product",
dy: {
query: {
  match_all: {}
}

n("data", function(res, err) {
nsole.log(res);
n("error", function(err) {
nsole.log("caught a stream error", err);

Console Output

ok: 1,
med_out: false,
hards: { 
total: 1, 
successful: 1, 
failed: 0

ts: {
total: 4,
max_score: 1,
hits: [ [Object], [Object], [Object], [Object] ] 


searchStream() also returns a stream.Readable object, which can be conveniently listened via the on("data") event listener. Check out the stream_search_test.js where we make an update that matches the query and see the results in the event stream.

API Reference

For a complete API reference, check out JS API Ref doc.

Global

new Appbase(args)

Returns a reference object on which streaming requests can be performed.

args - A set of key/value pairs that configures the ElasticSearch Index
    url: “https://scalr.api.appbase.io”
    app: App name (equivalent to an ElasticSearch Index)
    credentials: A username:password combination used for Basic Auth.

Optionally (and like in the quick example above), url can contain the credentials field in the format: https://<credentials>@scalr.appbase.io.

Reference

reference.getStream(args)

Get continuous updates on a JSON document with a type and id. Returns a stream.Readable object.

args - A set of key/value pairs that makes the document URL
    type: ElasticSearch Type, a string
    id: Valid Document ID

reference.searchStream(args)

Get continuous updates on search queries (fuzzy, boolean, geolocation, range, full-text). Returns a stream.Readable object.

args - A set of key/value pairs that makes the document URL
    type: ElasticSearch Type, a string
    body: A JSON Query Body (Any query matching the ElasticSearch Query DSL)


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.