-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from shikshalokam/master
remove ES
- Loading branch information
Showing
10 changed files
with
422 additions
and
469 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,103 +1,103 @@ | ||
/** | ||
* name : elasticSearch.js | ||
* author : Aman Jung Karki | ||
* created-date : 11-Jun-2020 | ||
* Description : elastic search common functionality | ||
*/ | ||
|
||
/** | ||
* Get user data | ||
* @function | ||
* @name get | ||
* @param {String} id - a unique document id | ||
* @param {String} index - elastic search index | ||
* @param {String} type - elastic search type | ||
* @returns {Object} Get user data. | ||
*/ | ||
|
||
var get = function ( | ||
id = "", | ||
index = "", | ||
type = "" | ||
) { | ||
|
||
return new Promise(async function (resolve, reject) { | ||
try { | ||
|
||
if (id == "") { | ||
throw new Error("ID is required"); | ||
} | ||
|
||
if (index == "") { | ||
throw new Error("Index is required"); | ||
} | ||
|
||
const result = await elasticsearch.client.get({ | ||
id: id, | ||
index: index | ||
}, { | ||
ignore: [httpStatusCode["not_found"].status], | ||
maxRetries: 3 | ||
}); | ||
|
||
return resolve(result); | ||
|
||
} catch (error) { | ||
return reject(error); | ||
} | ||
}) | ||
}; | ||
|
||
/** | ||
* Create or update based on user data. | ||
* @function | ||
* @name createOrUpdate | ||
* @param {String} id - a unique document id | ||
* @param {String} index - elastic search index | ||
* @param {String} data - requested data | ||
* @returns {Object} created or updated user data. | ||
*/ | ||
|
||
var createOrUpdate = function ( | ||
id = "", | ||
index = "", | ||
data = "" | ||
) { | ||
|
||
return new Promise(async function (resolve, reject) { | ||
try { | ||
|
||
if (id == "") { | ||
throw new Error("ID is required"); | ||
} | ||
|
||
if (index == "") { | ||
throw new Error("Index is required"); | ||
} | ||
|
||
if (Object.keys(data).length == 0) { | ||
throw new Error("Data is required"); | ||
} | ||
|
||
let result = | ||
await elasticsearch.client.update({ | ||
id : id, | ||
index : index, | ||
body : { | ||
doc : data , | ||
doc_as_upsert : true | ||
} | ||
}); | ||
|
||
return resolve(result); | ||
|
||
} catch (error) { | ||
return reject(error); | ||
} | ||
}) | ||
}; | ||
|
||
module.exports = { | ||
get : get, | ||
createOrUpdate : createOrUpdate | ||
}; | ||
// /** | ||
// * name : elasticSearch.js | ||
// * author : Aman Jung Karki | ||
// * created-date : 11-Jun-2020 | ||
// * Description : elastic search common functionality | ||
// */ | ||
|
||
// /** | ||
// * Get user data | ||
// * @function | ||
// * @name get | ||
// * @param {String} id - a unique document id | ||
// * @param {String} index - elastic search index | ||
// * @param {String} type - elastic search type | ||
// * @returns {Object} Get user data. | ||
// */ | ||
|
||
// var get = function ( | ||
// id = "", | ||
// index = "", | ||
// type = "" | ||
// ) { | ||
|
||
// return new Promise(async function (resolve, reject) { | ||
// try { | ||
|
||
// if (id == "") { | ||
// throw new Error("ID is required"); | ||
// } | ||
|
||
// if (index == "") { | ||
// throw new Error("Index is required"); | ||
// } | ||
|
||
// const result = await elasticsearch.client.get({ | ||
// id: id, | ||
// index: index | ||
// }, { | ||
// ignore: [httpStatusCode["not_found"].status], | ||
// maxRetries: 3 | ||
// }); | ||
|
||
// return resolve(result); | ||
|
||
// } catch (error) { | ||
// return reject(error); | ||
// } | ||
// }) | ||
// }; | ||
|
||
// * | ||
// * Create or update based on user data. | ||
// * @function | ||
// * @name createOrUpdate | ||
// * @param {String} id - a unique document id | ||
// * @param {String} index - elastic search index | ||
// * @param {String} data - requested data | ||
// * @returns {Object} created or updated user data. | ||
|
||
|
||
// var createOrUpdate = function ( | ||
// id = "", | ||
// index = "", | ||
// data = "" | ||
// ) { | ||
|
||
// return new Promise(async function (resolve, reject) { | ||
// try { | ||
|
||
// if (id == "") { | ||
// throw new Error("ID is required"); | ||
// } | ||
|
||
// if (index == "") { | ||
// throw new Error("Index is required"); | ||
// } | ||
|
||
// if (Object.keys(data).length == 0) { | ||
// throw new Error("Data is required"); | ||
// } | ||
|
||
// let result = | ||
// await elasticsearch.client.update({ | ||
// id : id, | ||
// index : index, | ||
// body : { | ||
// doc : data , | ||
// doc_as_upsert : true | ||
// } | ||
// }); | ||
|
||
// return resolve(result); | ||
|
||
// } catch (error) { | ||
// return reject(error); | ||
// } | ||
// }) | ||
// }; | ||
|
||
// module.exports = { | ||
// get : get, | ||
// createOrUpdate : createOrUpdate | ||
// }; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +0,0 @@ | ||
/** | ||
* name : elastic-search.js. | ||
* author : Aman Karki. | ||
* created-date : 02-Feb-2021. | ||
* Description : Elastic Search health check. | ||
*/ | ||
|
||
// Dependencies | ||
|
||
const { Client : esClient } = require('@elastic/elasticsearch'); | ||
|
||
function health_check() { | ||
return new Promise( async (resolve,reject) => { | ||
|
||
const elasticSearchClient = new esClient({ | ||
node: process.env.ELASTICSEARCH_HOST_URL | ||
}); | ||
|
||
elasticSearchClient.ping({ | ||
}, function (error) { | ||
if (error) { | ||
return resolve(false); | ||
} else { | ||
return resolve(true); | ||
} | ||
}); | ||
}) | ||
} | ||
|
||
module.exports = { | ||
health_check : health_check | ||
} | ||
Oops, something went wrong.