🔨 Clean up details

This commit is contained in:
Iván Ovejero 2021-05-21 14:49:11 +02:00
parent 1ee89639a8
commit 64ce0c6046
4 changed files with 39 additions and 36 deletions

View file

@ -20,6 +20,10 @@ import {
indexOperations,
} from './descriptions';
import {
DocumentGetAllAdditionalFields,
} from './types';
export class ElasticSearch implements INodeType {
description: INodeTypeDescription = {
displayName: 'ElasticSearch',
@ -132,11 +136,11 @@ export class ElasticSearch implements INodeType {
const body = {} as IDataObject;
const qs = {} as IDataObject;
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
const additionalFields = this.getNodeParameter('additionalFields', i) as DocumentGetAllAdditionalFields;
if (Object.keys(additionalFields).length) {
const { query, ...rest } = additionalFields;
Object.assign(body, query);
Object.assign(body, JSON.parse(query));
Object.assign(qs, rest);
}
@ -145,12 +149,9 @@ export class ElasticSearch implements INodeType {
if (!returnAll) {
qs.size = this.getNodeParameter('limit', 0);
}
responseData = await elasticSearchApiRequest.call(this, 'GET', `/${indexId}/_search`, body, qs);
responseData = responseData.hits.hits;
// TODO: Paginate
} else if (operation === 'index') {
// ----------------------------------------

View file

@ -51,7 +51,7 @@ export async function elasticSearchApiRequest(
}
try {
console.log(options);
// console.log(options);
return await this.helpers.request(options);
} catch (error) {
throw new NodeApiError(this.getNode(), error);

View file

@ -352,13 +352,13 @@ export const documentFields = [
typeOptions: {
minValue: 1,
},
default: 0,
default: 1,
},
{
displayName: 'Query',
name: 'query',
description: 'Query in the <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl.html" target="_blank">ElasticSearch Query DSL</a>.',
type: 'string',
type: 'json',
typeOptions: {
alwaysOpenEditWindow: true,
},
@ -372,13 +372,6 @@ export const documentFields = [
type: 'boolean',
default: false,
},
{
displayName: 'Rest Total Hits as Integer',
name: 'rest_total_hits_as_int',
description: 'Whether <code>hits.total</code> should be rendered as an integer or an object in the rest search response. Defaults to false.',
type: 'boolean',
default: false,
},
{
displayName: 'Routing',
name: 'routing',
@ -410,13 +403,6 @@ export const documentFields = [
type: 'boolean',
default: false,
},
{
displayName: 'Size',
name: 'size',
description: 'Define the number of hits to return. Defaults to 10.',
type: 'number',
default: 10,
},
{
displayName: 'Sort',
name: 'sort',
@ -459,20 +445,6 @@ export const documentFields = [
type: 'boolean',
default: false,
},
{
displayName: 'Suggest Field',
name: 'suggest_field',
description: 'Field to use for suggestions.',
type: 'string',
default: '',
},
{
displayName: 'Suggest Text',
name: 'suggest_text',
description: 'Source text for which the suggestions should be returned.',
type: 'string',
default: '',
},
{
displayName: 'Terminate After',
name: 'terminate_after',

View file

@ -3,3 +3,33 @@ export type ElasticSearchApiCredentials = {
password: string;
baseUrl: string;
};
export type DocumentGetAllAdditionalFields = {
allow_no_indices: boolean;
allow_partial_search_results: boolean;
batched_reduce_size: number;
ccs_minimize_roundtrips: boolean;
docvalue_fields: string;
expand_wildcards: 'All' | 'Closed' | 'Hidden' | 'None' | 'Open';
explain: boolean;
ignore_throttled: boolean;
ignore_unavailable: boolean;
max_concurrent_shard_requests: number;
pre_filter_shard_size: number;
query: string;
request_cache: boolean;
routing: string;
search_type: 'query_then_fetch' | 'dfs_query_then_fetch';
seq_no_primary_term: boolean;
sort: string;
_source: boolean;
_source_excludes: string;
_source_includes: string;
stats: string;
stored_fields: boolean;
terminate_after: boolean;
timeout: number;
track_scores: boolean;
track_total_hits: string;
version: boolean;
}