Skip to content

Commit 9c35f22

Browse files
committed
Merge with upstream, warn if query doesn't include METADATA which DSL adds by default - might be users are looking for by default.
1 parent a307db2 commit 9c35f22

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

lib/logstash/inputs/elasticsearch.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -366,15 +366,16 @@ def register
366366
def run(output_queue)
367367
if @schedule
368368
scheduler.cron(@schedule, :overlap => @schedule_overlap) do
369-
@query_executor.do_run(output_queue, get_query_object())
369+
@query_executor.do_run(output_queue, get_query_object)
370370
end
371371
scheduler.join
372372
else
373-
@query_executor.do_run(output_queue, get_query_object())
373+
@query_executor.do_run(output_queue, get_query_object)
374374
end
375375
end
376376

377377
def get_query_object
378+
return @query if @response_type == 'esql'
378379
if @cursor_tracker
379380
query = @cursor_tracker.inject_cursor(@query)
380381
@logger.debug("new query is #{query}")

lib/logstash/inputs/elasticsearch/esql.rb

+6-2
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,18 @@ def initialize(client, plugin)
1717
@plugin = plugin
1818
@retries = @plugin_params["retries"]
1919
@query = @plugin_params["query"]
20+
unless @query.include?('METADATA')
21+
logger.warn("The query doesn't have METADATA keyword. Including it makes _id and _version available in the documents", {:query => @query})
22+
end
2023
end
2124

2225
# Execute the ESQL query and process results
2326
# @param output_queue [Queue] The queue to push processed events to
24-
def do_run(output_queue)
27+
# @param query A query to be executed
28+
def do_run(output_queue, query)
2529
logger.info("ES|QL executor starting")
2630
response = retryable(ESQL_JOB) do
27-
@client.esql.query({ body: { query: @query }, format: 'json' })
31+
@client.esql.query({ body: { query: query }, format: 'json' })
2832
end
2933
# retriable already printed error details
3034
return if response == false

0 commit comments

Comments
 (0)