mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
✨ Add Elasticsearch node (#1791)
* 🎉 Initial node scaffolding * ⚡ Implement index operations * ⚡ Implement document operations * 🔨 Clean up details * 🔨 Fix casing * 🔨 Fix indentation * ⚡ Minor fixes * ✏️ Update descriptions * 🔥 Remove wrong placeholder * ⚡ Refactor to implement specifyIndexBy * 👕 Appease linter * Revert "⚡ Refactor to implement specifyIndexBy" This reverts commit 02ea0d30804b14f0b489678cd4e5deeb95848883. * 🔥 Remove unused file * ⚡ Return source always in document:get and getAll * ⚡ Rename to options in document:getAll * ⚡ Rename to options in document:get * ⚡ Send content as JSON * ⚡ Add simplify param to document:get * ⚡ Rename docvalue fields * ⚡ Make document ID optional in document:index * ⚡ Implement sendInputData * 👕 Fix lintings * Add define and automap to document:index * WIP on document:update * 🔨 Adjust document:update per feedback * 🔥 Remove logging * ⚡ Improve Elasticsearch node Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
This commit is contained in:
58
packages/nodes-base/nodes/Elasticsearch/GenericFunctions.ts
Normal file
58
packages/nodes-base/nodes/Elasticsearch/GenericFunctions.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import {
|
||||
OptionsWithUri,
|
||||
} from 'request';
|
||||
|
||||
import {
|
||||
IExecuteFunctions,
|
||||
} from 'n8n-core';
|
||||
|
||||
import {
|
||||
IDataObject,
|
||||
NodeApiError,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import {
|
||||
ElasticsearchApiCredentials,
|
||||
} from './types';
|
||||
|
||||
export async function elasticsearchApiRequest(
|
||||
this: IExecuteFunctions,
|
||||
method: 'GET' | 'PUT' | 'POST' | 'DELETE',
|
||||
endpoint: string,
|
||||
body: IDataObject = {},
|
||||
qs: IDataObject = {},
|
||||
) {
|
||||
const {
|
||||
username,
|
||||
password,
|
||||
baseUrl,
|
||||
} = this.getCredentials('elasticsearchApi') as ElasticsearchApiCredentials;
|
||||
|
||||
const token = Buffer.from(`${username}:${password}`).toString('base64');
|
||||
|
||||
const options: OptionsWithUri = {
|
||||
headers: {
|
||||
Authorization: `Basic ${token}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
method,
|
||||
body,
|
||||
qs,
|
||||
uri: `${baseUrl}${endpoint}`,
|
||||
json: true,
|
||||
};
|
||||
|
||||
if (!Object.keys(body).length) {
|
||||
delete options.body;
|
||||
}
|
||||
|
||||
if (!Object.keys(qs).length) {
|
||||
delete options.qs;
|
||||
}
|
||||
|
||||
try {
|
||||
return await this.helpers.request(options);
|
||||
} catch (error) {
|
||||
throw new NodeApiError(this.getNode(), error);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user