A flexibe and configurable module to connect Firebase with Elasticsearch.
- Easily configure the way how the data should be taken from Firebase
- Filter out documents
- Include and exclude specific fields
- Support for joins
# Using npm
npm install --save elasticfire
# Using yarn
yarn add elasticfire
const ElasticFire = require("elasticfire");
// Initialize the ElasticFire instance
let ef = new ElasticFire({
// Set the Firebase configuration
firebase: {
apiKey: "AI...BY",
authDomain: "em...d.firebaseapp.com",
databaseURL: "https://em...d.firebaseio.com",
storageBucket: "em...d.appspot.com",
messagingSenderId: "95...36"
}
// Firebase paths and how to index them in Elasticsearch
, paths: [
{
// Firebase path
path : "articles"
// Elasticsearch index and type
, index: "articles"
, type : "article"
// Optional joined fields
, joins: [
// The `author` is a field from the article
// which points to the `users` collection.
{
path: "users"
, name: "author"
}
// If we have an array of comment ids, pointing
// to another collection, then they will be joined too
, {
path: "comments"
, name: "comments"
}
]
// Filter out some data
, filter: (data, snap) => snap.key !== "_id"
}
]
});
// Listen for the events emitted by
// the ElasticFire instanceand output some data
ef.on("error", err => {
console.error(err);
}).on("index_created", name => {
console.log(`${name} created`);
}).on("index_updated", name => {
console.log(`${name} updated`);
}).on("index_deleted", name => {
console.log(`${name} deleted`);
});
There are few ways to get help:
- Please post questions on Stack Overflow. You can open issues with questions, as long you add a link to your Stack Overflow question.
- For bug reports and feature requests, open issues. 🐛
Creates a new instance of ElasticFire
.
- Object
config
: An object containing the following fields:- paths (Array): An array of objects to configure the way how the
data is taken from Firebase:
-
index
(String): The Elasticsearch index name. -
type
(String): The Elasticsearch type name. -
joins
(Array): An array of objects configuring the joins:name
(String): The field which is an id pointing to another collection in Firebase.path
(String): The Firebase collection path where the the ids are pointing to.
-
fields
(Array): An array of dot-notation strings representing the fields to include in the objects. -
omit
(Array): An array of dot-notation strings representing the fields to omit. -
filter
(Function): A function to filter the objects (if it returnsfalse
, the object is not indexed). The function receives as arguments thedata
object and thesnapshot
.By default, all the objects from a path are indexed.
-
firebase
(Object): The Firebase configuration.- elasticSearch (Object): The Elasticsearch configuration:
- host (String): The Elasticsearch host (default:
localhost
). - port (Number): The Elasticsearch port (default:
9200
). - auth (Object): The credentials.
- user (String): The user to be used.
- pass (String): The password to be used.
- host (String): The Elasticsearch host (default:
- paths (Array): An array of objects to configure the way how the
data is taken from Firebase:
- ElasticFire The
ElasticFire
instance.
Triggers the search in Elasticsearch.
Have an idea? Found a bug? See how to contribute.
flashlight
was the main inspiration for this project. 🍰