-
Notifications
You must be signed in to change notification settings - Fork 846
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
915b39c
commit 6a0249d
Showing
10 changed files
with
70 additions
and
87 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
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
const jsonParser = require('../../jsonparser.js') | ||
const aws4signer = require('../../aws4signer') | ||
const _ = require('lodash') | ||
|
||
class Serverless { | ||
async getOpenSearchServerlessData (limit, offset, callback) { | ||
const searchBody = await this.searchWithTemplate(this.searchBody) | ||
searchBody.size = limit | ||
searchBody.from = offset | ||
const additionalParams = this.paramsToString(this.parent.options[`${this.options.type}-params`] || this.parent.options.params, '&') | ||
// Note: OpenSearch Serverless does not support _search?scroll API. As a workaround pure _search is used | ||
// List of supported endpoints: https://docs.aws.amazon.com/opensearch-service/latest/developerguide/serverless-genref.html#serverless-operations | ||
const uri = `${this.base.url}/_search${additionalParams}` | ||
|
||
const searchRequest = { | ||
uri, | ||
method: 'GET', | ||
body: jsonParser.stringify(searchBody) | ||
} | ||
aws4signer(searchRequest, this.parent).then((res) => { | ||
this.baseRequest(searchRequest, (err, response) => { | ||
err = this.handleError(err, response) | ||
if (err) { | ||
return callback(err, []) | ||
} | ||
|
||
const body = jsonParser.parse(response.body, this.parent) | ||
const hits = _.get(body, 'hits.hits', []) | ||
|
||
if (hits.length < limit) { | ||
// No more data to fetch | ||
callback(null, hits) | ||
} else { | ||
this.getOpenSearchServerlessData(limit, offset + limit, (err, moreHits) => { | ||
if (err) { | ||
return callback(err, []) | ||
} | ||
callback(null, hits.concat(moreHits)) | ||
}) | ||
} | ||
}) | ||
}).catch(callback) | ||
} | ||
} | ||
|
||
module.exports = Serverless |
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