@@ -18,9 +18,15 @@ class Esql
1818 def initialize ( client , plugin )
1919 @client = client
2020 @event_decorator = plugin . method ( :decorate_event )
21- @target_field = plugin . params [ "target" ]
2221 @retries = plugin . params [ "retries" ]
2322
23+ target_field = plugin . params [ "target" ]
24+ if target_field
25+ def self . apply_target ( path ) = "[#{ target_field } ][#{ path } ]"
26+ else
27+ def self . apply_target ( path ) = path
28+ end
29+
2430 @query = plugin . params [ "query" ]
2531 unless @query . include? ( 'METADATA' )
2632 logger . info ( "`METADATA` not found the query. `_id`, `_version` and `_index` will not be available in the result" , { :query => @query } )
@@ -40,7 +46,7 @@ def do_run(output_queue, query)
4046 return if response == false
4147
4248 if response &.headers &.dig ( "warning" )
43- logger . warn ( "ES|QL executor received warning" , { :message => response . headers [ "warning" ] } )
49+ logger . warn ( "ES|QL executor received warning" , { :warning_message => response . headers [ "warning" ] } )
4450 end
4551 columns = response [ 'columns' ] &.freeze
4652 values = response [ 'values' ] &.freeze
@@ -76,7 +82,7 @@ def process_response(columns, values, output_queue)
7682 # `unless value.nil?` is a part of `drop_null_columns` that if some of columns' values are not `nil`, `nil` values appear
7783 # we should continuously filter out them to achieve full `drop_null_columns` on each individual row (ideal `LIMIT 1` result)
7884 unless value . nil?
79- field_reference = @target_field . nil? ? column . field_reference : "[ #{ @target_field } ][ #{ column . field_reference } ]"
85+ field_reference = apply_target ( column . field_reference )
8086 event . set ( field_reference , ESQL_PARSERS_BY_TYPE [ column . type ] . call ( value ) )
8187 end
8288 end
0 commit comments