# Join query with Elasticsearch and Firebase

**URL:** <https://discuss.elastic.co/t/join-query-with-elasticsearch-and-firebase/85206>\
**Category:** Elasticsearch\
**Created:** [May 10, 2017, 8:53am UTC](https://discuss.elastic.co/t/join-query-with-elasticsearch-and-firebase/85206 "2017-05-10T08:53:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![elasticDev](https://avatars.discourse-cdn.com/v4/letter/e/bc79bd/32.png) [@elasticDev](https://discuss.elastic.co/u/elasticDev)\
**Post date:** [May 10, 2017, 8:53am UTC](https://discuss.elastic.co/t/join-query-with-elasticsearch-and-firebase/85206/1 "2017-05-10T08:53:30Z")

</div>

Hi all,  
I need to do a join query on firebase using elasticsearch,  
can anyone help me?  
In particular I have two nodes, in the child node I have a field that is the id of the father node  
and I would like to have as a result all the fields of the father node.  
How do I build my index in the code?  
In adding, in my client I use elasticsearchclient, (I'm implementing on NodeJS),  
here is an extract of the code to index a node:

var db = admin.database();  
var etest = db.ref(type);  
etest.on('child\_added', createOrUpdateIndex);  
etest.on('child\_changed', createOrUpdateIndex);  
etest.on('child\_removed', removeIndex);

function createOrUpdateIndex(snap) {

client.index(index, type, snap.val(), snap.key)  
.on('data', function(data) { console.log('indexed', snap.key + data ); })  
.on('error', function(err) { console.log('index error ', err); }).exec();  
}

function removeIndex(snap) {  
client.deleteDocument(index, type, snap.key, function(error, data) {  
if( error ) console.error('failed to delete', snap.key, error);  
else console.log('deleted', snap.key);  
});  
}

And to take query results:

var queue = db.ref("search");  
queue.child('request').on('child\_added', processRequest);

function processRequest(snap) {  
console.log('process...... ');  
snap.ref.remove(); // clear the request after we receive it  
var data = snap.val();  
// Query ElasticSearch  
client.search(index, data.type, { "query": { 'query\_string': {  
"query" : data.query  
}}})

.on('data', function(results) {  
var res = JSON.parse(results);  
console.log(JSON.stringify(res.hits));  
console.log("TOTAL " + JSON.stringify(res.hits.total));  
queue.child('response/'+snap.key).set(results);  
})

.on('error', function(error){ console.log("errore"); }).exec();

}

Thank you in advance

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 7, 2017, 9:07am UTC](https://discuss.elastic.co/t/join-query-with-elasticsearch-and-firebase/85206/2 "2017-06-07T09:07:40Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
