0

Here is how my Firebase Schema is laid out: enter image description here

I am able to index everything except _geoloc: into my Algolia Index with this code:

'use strict';

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);

// Authenticate to Algolia Database.
// TODO: Make sure you configure the `algolia.app_id` and `algolia.api_key` Google Cloud environment variables.
const algoliasearch = require('algoliasearch');
const client = algoliasearch(functions.config().algolia.app_id, functions.config().algolia.api_key);

// Name fo the algolia index for content.
const ALGOLIA_POSTS_INDEX_NAME = 'businessSearch';


exports.indexentry = functions.database.ref('/businessSearch/{uid}/').onWrite(event => {
    const index = client.initIndex(ALGOLIA_POSTS_INDEX_NAME);
    const firebaseObject = Object.assign({}, event.data.val(), {
      functions.database.ref('/businessSearch/{uid}/_geoloc').onWrite(event =>{

      })
      objectID: event.params.uid,
    });

    index.saveObject(firebaseObject); // .then or .catch as well
    index.addObject
  });

How can I index the _geoloc: child node into my Algolia Index with Node.js?

I heard somewhere that this is not possible to index a nested object with Object.assign, but I just wanted to see if it was.

AL.
  • 36,815
  • 10
  • 142
  • 281
ethanfox27
  • 890
  • 1
  • 9
  • 25
  • Very confused as to what you're trying to do here. An `onWrite` on `/businessSearch/{uid}` will include `_geoloc` in its `event.data.val()` payload -- you don't need to listen to the child node separately. – Michael Bleigh May 17 '17 at 19:43
  • No, it does not. I am indexing to my Algolia Search Index. Where only the address, businessName, and businessType get Indexed not _geoloc – ethanfox27 May 17 '17 at 19:46
  • This seems like an issue with Algolia, not Firebase. If you do a `console.log(event.data.val())` you ought to see `_geoloc`. Perhaps Algolia ignores underscored fields by default? – Michael Bleigh May 17 '17 at 19:51
  • Seems to be a timing issue when the database is updated I manually added another value key pair and _geoloc was then added. – ethanfox27 May 17 '17 at 19:58

1 Answers1

0

There is a timing issue when the database is written and what gets indexed by Algolia. The code included in my question does work with nested objects.

ethanfox27
  • 890
  • 1
  • 9
  • 25