elasticsearch end to end

This commit is contained in:
Martin McKeaveney 2020-11-26 17:03:18 +00:00
parent fbf501aebc
commit 5e5b489cb9
5 changed files with 112 additions and 2 deletions

View File

@ -51,6 +51,7 @@
"license": "AGPL-3.0-or-later",
"dependencies": {
"@budibase/client": "^0.3.8",
"@elastic/elasticsearch": "^7.10.0",
"@koa/router": "^8.0.0",
"@sendgrid/mail": "^7.1.1",
"@sentry/node": "^5.19.2",

View File

@ -0,0 +1,43 @@
// const PouchDB = require("pouchdb")
// const COUCHDB_OPTIONS = {
// url: {
// type: "string",
// required: true,
// default: "localhost",
// },
// database: {
// type: "string",
// required: true,
// },
// // query: {
// // type: "query",
// // required: true,
// // },
// }
// class ElasticSearchIntegration {
// constructor(config) {
// this.config = config
// this.client = new Client({ node: config.url })
// }
// async query() {
// try {
// const result = await this.client.search({
// index: this.config.index,
// body: JSON.parse(this.config.query),
// })
// return result
// } finally {
// await this.client.close()
// }
// }
// }
// module.exports = {
// schema: ELASTICSEARCH_OPTIONS,
// integration: ElasticSearchIntegration,
// }

View File

@ -0,0 +1,41 @@
const { Client } = require("@elastic/elasticsearch")
const ELASTICSEARCH_OPTIONS = {
url: {
type: "string",
required: true,
default: "localhost",
},
index: {
type: "string",
required: true,
},
query: {
type: "query",
required: true,
},
}
class ElasticSearchIntegration {
constructor(config) {
this.config = config
this.client = new Client({ node: config.url })
}
async query() {
try {
const result = await this.client.search({
index: this.config.index,
body: JSON.parse(this.config.query),
})
return result.body.hits.hits.map(({ _source }) => _source)
} finally {
await this.client.close()
}
}
}
module.exports = {
schema: ELASTICSEARCH_OPTIONS,
integration: ElasticSearchIntegration,
}

View File

@ -1,21 +1,25 @@
const postgres = require("./postgres")
const dynamodb = require("./dynamodb")
const mongodb = require("./mongodb")
const elasticsearch = require("./elasticsearch")
const couchdb = require("./couchdb")
// const redis = require("./redis")
// const couchdb = require("./couchdb")
// const elasticsearch = require("./elasticsearch")
// const s3 = require("./s3")
const DEFINITIONS = {
POSTGRES: postgres.schema,
DYNAMODB: dynamodb.schema,
MONGODB: mongodb.schema,
ELASTICSEARCH: elasticsearch.schema,
COUCHDB: couchdb.schema,
}
const INTEGRATIONS = {
POSTGRES: postgres.integration,
DYNAMODB: dynamodb.integration,
MONGODB: mongodb.integration,
ELASTICSEARCH: elasticsearch.integration,
COUCHDB: couchdb.integration,
}
module.exports = {

View File

@ -225,6 +225,17 @@
ajv "^6.12.0"
ajv-keywords "^3.4.1"
"@elastic/elasticsearch@^7.10.0":
version "7.10.0"
resolved "https://registry.yarnpkg.com/@elastic/elasticsearch/-/elasticsearch-7.10.0.tgz#da105a9c1f14146f9f2cab4e7026cb7949121b8d"
integrity sha512-vXtMAQf5/DwqeryQgRriMtnFppJNLc/R7/R0D8E+wG5/kGM5i7mg+Hi7TM4NZEuXgtzZ2a/Nf7aR0vLyrxOK/w==
dependencies:
debug "^4.1.1"
hpagent "^0.1.1"
ms "^2.1.1"
pump "^3.0.0"
secure-json-parse "^2.1.0"
"@electron/get@^1.0.1":
version "1.12.2"
resolved "https://registry.yarnpkg.com/@electron/get/-/get-1.12.2.tgz#6442066afb99be08cefb9a281e4b4692b33764f3"
@ -3650,6 +3661,11 @@ hosted-git-info@^3.0.5:
dependencies:
lru-cache "^6.0.0"
hpagent@^0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/hpagent/-/hpagent-0.1.1.tgz#66f67f16e5c7a8b59a068e40c2658c2c749ad5e2"
integrity sha512-IxJWQiY0vmEjetHdoE9HZjD4Cx+mYTr25tR7JCxXaiI3QxW0YqYyM11KyZbHufoa/piWhMb2+D3FGpMgmA2cFQ==
html-encoding-sniffer@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/html-encoding-sniffer/-/html-encoding-sniffer-1.0.2.tgz#e70d84b94da53aa375e11fe3a351be6642ca46f8"
@ -6987,6 +7003,11 @@ sax@>=0.6.0, sax@^1.2.4:
resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9"
integrity sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==
secure-json-parse@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/secure-json-parse/-/secure-json-parse-2.1.0.tgz#ae76f5624256b5c497af887090a5d9e156c9fb20"
integrity sha512-GckO+MS/wT4UogDyoI/H/S1L0MCcKS1XX/vp48wfmU7Nw4woBmb8mIpu4zPBQjKlRT88/bt9xdoV4111jPpNJA==
seek-bzip@^1.0.5:
version "1.0.6"
resolved "https://registry.yarnpkg.com/seek-bzip/-/seek-bzip-1.0.6.tgz#35c4171f55a680916b52a07859ecf3b5857f21c4"