Created
December 6, 2019 11:40
-
-
Save dnek/439bf98463fb23689c6df94ff111ca9e to your computer and use it in GitHub Desktop.
Firebase Cloud Functions x ElasticSearch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const functions = require('firebase-functions') | |
const { Client } = require('@elastic/elasticsearch') | |
const config = { | |
cloud: { | |
id: 'xxx' | |
}, | |
auth: { | |
username: 'xxx', | |
password: 'xxx' | |
} | |
} | |
const client = new Client(config) | |
exports.mySearchFunc = functions.region('asia-northeast1').https.onCall(async (data, context) => { | |
const result = await client.search({ | |
index: 'xxx', | |
body: { | |
query: { | |
match_all: {} | |
} | |
} | |
}).catch(console.log) | |
return result.body.hits.hits | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment