From b13e3d671dce3815ba0c4f24466f733be11a1fea Mon Sep 17 00:00:00 2001 From: Shruti Mantri Date: Thu, 5 Sep 2024 15:51:20 +0530 Subject: [PATCH] fix(docs): add full examples for elasticsearch tasks --- .../io/kestra/plugin/elasticsearch/Bulk.java | 23 ++++-- .../io/kestra/plugin/elasticsearch/Get.java | 21 +++-- .../io/kestra/plugin/elasticsearch/Load.java | 25 ++++-- .../io/kestra/plugin/elasticsearch/Put.java | 55 ++++++++----- .../kestra/plugin/elasticsearch/Request.java | 79 ++++++++++++------- .../kestra/plugin/elasticsearch/Scroll.java | 31 +++++--- .../kestra/plugin/elasticsearch/Search.java | 31 +++++--- 7 files changed, 174 insertions(+), 91 deletions(-) diff --git a/src/main/java/io/kestra/plugin/elasticsearch/Bulk.java b/src/main/java/io/kestra/plugin/elasticsearch/Bulk.java index 8d4d027..8c99783 100644 --- a/src/main/java/io/kestra/plugin/elasticsearch/Bulk.java +++ b/src/main/java/io/kestra/plugin/elasticsearch/Bulk.java @@ -38,12 +38,23 @@ @Plugin( examples = { @Example( - code = { - "connection:", - " hosts: ", - " - \"http://localhost:9200\"", - "from: \"{{ inputs.file }}\"" - } + full = true, + code = """ + id: elasticsearch_bulk_load + namespace: company.team + + inputs: + - id: file + type: FILE + + tasks: + - id: bulk_load + type: io.kestra.plugin.elasticsearch.Bulk + connection: + hosts: + - "http://localhost:9200" + from: "{{ inputs.file }}" + """ ) } ) diff --git a/src/main/java/io/kestra/plugin/elasticsearch/Get.java b/src/main/java/io/kestra/plugin/elasticsearch/Get.java index 48c3464..06d3dc3 100644 --- a/src/main/java/io/kestra/plugin/elasticsearch/Get.java +++ b/src/main/java/io/kestra/plugin/elasticsearch/Get.java @@ -28,13 +28,20 @@ @Plugin( examples = { @Example( - code = { - "connection:", - " hosts: ", - " - \"http://localhost:9200\"", - "index: \"my_index\"", - "key: \"my_id\"", - } + full = true, + code = """ + id: elasticsearch_get + namespace: company.team + + tasks: + - id: get + type: io.kestra.plugin.elasticsearch.Get + connection: + hosts: + - "http://localhost:9200" + index: "my_index" + key: "my_id" + """ ) } ) diff --git a/src/main/java/io/kestra/plugin/elasticsearch/Load.java b/src/main/java/io/kestra/plugin/elasticsearch/Load.java index 869ddb8..31a9e47 100644 --- a/src/main/java/io/kestra/plugin/elasticsearch/Load.java +++ b/src/main/java/io/kestra/plugin/elasticsearch/Load.java @@ -33,13 +33,24 @@ @Plugin( examples = { @Example( - code = { - "connection:", - " hosts: ", - " - \"http://localhost:9200\"", - "from: \"{{ inputs.file }}\"", - "index: \"my_index\"", - } + full = true, + code = """ + id: elasticsearch_load + namespace: company.team + + inputs: + - id: file + type: FILE + + tasks: + - id: load + type: io.kestra.plugin.elasticsearch.Load + connection: + hosts: + - "http://localhost:9200" + from: "{{ inputs.file }}" + index: "my_index" + """ ) } ) diff --git a/src/main/java/io/kestra/plugin/elasticsearch/Put.java b/src/main/java/io/kestra/plugin/elasticsearch/Put.java index 8403259..704e639 100644 --- a/src/main/java/io/kestra/plugin/elasticsearch/Put.java +++ b/src/main/java/io/kestra/plugin/elasticsearch/Put.java @@ -37,27 +37,46 @@ examples = { @Example( title = "Put a document with a Map.", - code = { - "connection:", - " hosts: ", - " - \"http://localhost:9200\"", - "index: \"my_index\"", - "key: \"my_id\"", - "value:", - " name: \"John Doe\"", - " city: \"Paris\"", - } + full = true, + code = """ + id: elasticsearch_put + namespace: company.team + + tasks: + - id: put + type: io.kestra.plugin.elasticsearch.Put + connection: + hosts: + - "http://localhost:9200" + index: "my_index" + key: "my_id" + value: + name: "John Doe" + city: "Paris" + """ ), @Example( title = "Put a document from a JSON string.", - code = { - "connection:", - " hosts: ", - " - \"http://localhost:9200\"", - "index: \"my_index\"", - "key: \"my_id\"", - "value: \"{{ outputs.task_id.data | json }}\"" - } + full = true, + code = """ + id: elasticsearch_put + namespace: company.team + + inputs: + - id: value + type: JSON + defaults: {"name": "John Doe", "city": "Paris"} + + tasks: + - id: put + type: io.kestra.plugin.elasticsearch.Put + connection: + hosts: + - "http://localhost:9200" + index: "my_index" + key: "my_id" + value: "{{ inputs.value }}" + """ ), } ) diff --git a/src/main/java/io/kestra/plugin/elasticsearch/Request.java b/src/main/java/io/kestra/plugin/elasticsearch/Request.java index 474a71c..26b6e89 100644 --- a/src/main/java/io/kestra/plugin/elasticsearch/Request.java +++ b/src/main/java/io/kestra/plugin/elasticsearch/Request.java @@ -34,50 +34,71 @@ examples = { @Example( title = "Inserting a document in an index using POST request.", - code = { - "connection:", - " hosts: ", - " - \"http://localhost:9200\"", - "method: \"POST\"", - "endpoint: \"my_index/_doc/john\"", - "body:", - " name: \"john\"" - } + full = true, + code = """ + id: elasticsearch_request + namespace: company.team + + tasks: + - id: request_post + type: io.kestra.plugin.elasticsearch.Request + connection: + hosts: + - "http://localhost:9200" + method: "POST" + endpoint: "my_index/_doc/john" + body: + name: "john" + """ ), @Example( title = "Searching for documents using GET request.", - code = { - "connection:", - " hosts: ", - " - \"http://localhost:9200\"", - "method: \"GET\"", - "endpoint: \"my_index/_search\"", - "parameters:", - " q: \"name:\\\"John Doe\\\"" - } + full = true, + code = """ + id: elasticsearch_request + namespace: company.team + + tasks: + - id: request_get + type: io.kestra.plugin.elasticsearch.Request + connection: + hosts: + - "http://localhost:9200" + method: "GET" + endpoint: "my_index/_search" + parameters: + q: "name:\"John Doe\"" + """ ), @Example( title = "Deleting document using DELETE request.", - code = { - "connection:", - " hosts: ", - " - \"http://localhost:9200\"", - "method: \"DELETE\"", - "endpoint: \"my_index/_doc/<_id>\"", - } + full = true, + code = """ + id: elasticsearch_request + namespace: company.team + + tasks: + - id: request_delete + type: io.kestra.plugin.elasticsearch.Request + connection: + hosts: + - "http://localhost:9200" + method: "DELETE" + endpoint: "my_index/_doc/<_id>" + """ ), } ) public class Request extends AbstractTask implements RunnableTask { @Schema( - title = "The http method to use" + title = "The http method to use." ) @Builder.Default @PluginProperty protected HttpMethod method = HttpMethod.GET; @Schema( - title = "The path of the request (without scheme, host, port, or prefix)" + title = "The path of the request (without scheme, host, port, or prefix)." ) @PluginProperty(dynamic = true) protected String endpoint; @@ -89,8 +110,8 @@ public class Request extends AbstractTask implements RunnableTask parameters; @Schema( - title = "The full body", - description = "Can be a json string or raw Map that will be converted to json" + title = "The full body.", + description = "Can be a JSON string or raw Map that will be converted to json." ) @PluginProperty(dynamic = true) protected Object body; diff --git a/src/main/java/io/kestra/plugin/elasticsearch/Scroll.java b/src/main/java/io/kestra/plugin/elasticsearch/Scroll.java index 9964aa0..fdf2d51 100644 --- a/src/main/java/io/kestra/plugin/elasticsearch/Scroll.java +++ b/src/main/java/io/kestra/plugin/elasticsearch/Scroll.java @@ -39,18 +39,25 @@ @Plugin( examples = { @Example( - code = { - "connection:", - " hosts: ", - " - \"http://localhost:9200\"", - "indexes:", - " - \"my_index\"", - "request:", - " query: ", - " term:", - " name:", - " value: 'john'", - } + full = true, + code = """ + id: elasticsearch_scroll + namespace: company.team + + tasks: + - id: scroll + type: io.kestra.plugin.elasticsearch.Scroll + connection: + hosts: + - "http://localhost:9200" + indexes: + - "my_index" + request: + query: + term: + name: + value: 'john' + """ ) } ) diff --git a/src/main/java/io/kestra/plugin/elasticsearch/Search.java b/src/main/java/io/kestra/plugin/elasticsearch/Search.java index 4db5fd1..5a1b0e3 100644 --- a/src/main/java/io/kestra/plugin/elasticsearch/Search.java +++ b/src/main/java/io/kestra/plugin/elasticsearch/Search.java @@ -42,18 +42,25 @@ @Plugin( examples = { @Example( - code = { - "connection:", - " hosts: ", - " - \"http://localhost:9200\"", - "indexes:", - " - \"my_index\"", - "request:", - " query: ", - " term:", - " name:", - " value: 'john'", - } + full = true, + code = """ + id: elasticsearch_search + namespace: company.team + + tasks: + - id: search + type: io.kestra.plugin.elasticsearch.Search + connection: + hosts: + - "http://localhost:9200" + indexes: + - "my_index" + request: + query: + term: + name: + value: 'john' + """ ) } )