Skip to content

🔥 A flexibe and configurable module to connect Firebase with Elasticsearch.

License

Notifications You must be signed in to change notification settings

Bloggify/elasticfire

Repository files navigation

elasticfire

elasticfire

Version Downloads

A flexibe and configurable module to connect Firebase with Elasticsearch.

🚀 Features

  • Easily configure the way how the data should be taken from Firebase
  • Filter out documents
  • Include and exclude specific fields
  • Support for joins

☁️ Installation

# Using npm
npm install --save elasticfire

# Using yarn
yarn add elasticfire

📋 Example

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`);
});

❓ Get Help

There are few ways to get help:

  1. Please post questions on Stack Overflow. You can open issues with questions, as long you add a link to your Stack Overflow question.
  2. For bug reports and feature requests, open issues. 🐛

📝 Documentation

ElasticFire(config)

Creates a new instance of ElasticFire.

Params

  • 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 returns false, the object is not indexed). The function receives as arguments the data object and the snapshot.

        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.

Return

  • ElasticFire The ElasticFire instance.

search()

Triggers the search in Elasticsearch.

😋 How to contribute

Have an idea? Found a bug? See how to contribute.

🍰 Thanks

flashlight was the main inspiration for this project. 🍰

📜 License

MIT © Bloggify

About

🔥 A flexibe and configurable module to connect Firebase with Elasticsearch.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published