Skip to content

Commit

Permalink
Merge pull request #14 from shrutimantri/add-full-examples
Browse files Browse the repository at this point in the history
fix(docs): add full examples for elasticsearch tasks
  • Loading branch information
wrussell1999 authored Sep 5, 2024
2 parents d9c23be + b13e3d6 commit a2c0820
Show file tree
Hide file tree
Showing 7 changed files with 174 additions and 91 deletions.
23 changes: 17 additions & 6 deletions src/main/java/io/kestra/plugin/elasticsearch/Bulk.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
"""
)
}
)
Expand Down
21 changes: 14 additions & 7 deletions src/main/java/io/kestra/plugin/elasticsearch/Get.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"
"""
)
}
)
Expand Down
25 changes: 18 additions & 7 deletions src/main/java/io/kestra/plugin/elasticsearch/Load.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"
"""
)
}
)
Expand Down
55 changes: 37 additions & 18 deletions src/main/java/io/kestra/plugin/elasticsearch/Put.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
"""
),
}
)
Expand Down
79 changes: 50 additions & 29 deletions src/main/java/io/kestra/plugin/elasticsearch/Request.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Request.Output> {
@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;
Expand All @@ -89,8 +110,8 @@ public class Request extends AbstractTask implements RunnableTask<Request.Output
protected Map<String, String> 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;
Expand Down
31 changes: 19 additions & 12 deletions src/main/java/io/kestra/plugin/elasticsearch/Scroll.java
Original file line number Diff line number Diff line change
Expand Up @@ -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'
"""
)
}
)
Expand Down
31 changes: 19 additions & 12 deletions src/main/java/io/kestra/plugin/elasticsearch/Search.java
Original file line number Diff line number Diff line change
Expand Up @@ -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'
"""
)
}
)
Expand Down

0 comments on commit a2c0820

Please sign in to comment.