You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Introduce cursor tracking akin to jdbc input (#205)
Provide field value tracking, persisted to disk on each search_after page.
Adds `:last_value` and `:present` placeholders, allowing the plugin to inject the cursor value and now-30 seconds, respectively, in the query string.
Useful to track new data being written to an index or series of indices.
Works best with nano second precision timestamps added by Elasticsearch's Ingest Pipelines.
---------
Co-authored-by: Joel Andritsch <[email protected]>
Co-authored-by: Rob Bavey <[email protected]>
Co-authored-by: Karen Metts <[email protected]>
Copy file name to clipboardExpand all lines: CHANGELOG.md
+3
Original file line number
Diff line number
Diff line change
@@ -1,3 +1,6 @@
1
+
## 5.1.0
2
+
- Add "cursor"-like index tracking [#205](https://github.com/logstash-plugins/logstash-input-elasticsearch/pull/205)
3
+
1
4
## 5.0.2
2
5
- Add elastic-transport client support used in elasticsearch-ruby 8.x [#223](https://github.com/logstash-plugins/logstash-input-elasticsearch/pull/223)
Copy file name to clipboardExpand all lines: docs/index.asciidoc
+178-1
Original file line number
Diff line number
Diff line change
@@ -48,7 +48,7 @@ This would create an Elasticsearch query with the following format:
48
48
"sort": [ "_doc" ]
49
49
}'
50
50
51
-
51
+
[id="plugins-{type}s-{plugin}-scheduling"]
52
52
==== Scheduling
53
53
54
54
Input from this plugin can be scheduled to run periodically according to a specific
@@ -103,6 +103,133 @@ Common causes are:
103
103
- When the hit result contains top-level fields that are {logstash-ref}/processing.html#reserved-fields[reserved in Logstash] but do not have the expected shape. Use the <<plugins-{type}s-{plugin}-target>> directive to avoid conflicts with the top-level namespace.
104
104
- When <<plugins-{type}s-{plugin}-docinfo>> is enabled and the docinfo fields cannot be merged into the hit result. Combine <<plugins-{type}s-{plugin}-target>> and <<plugins-{type}s-{plugin}-docinfo_target>> to avoid conflict.
105
105
106
+
[id="plugins-{type}s-{plugin}-cursor"]
107
+
==== Tracking a field's value across runs
108
+
109
+
.Technical Preview: Tracking a field's value
110
+
****
111
+
The feature that allows tracking a field's value across runs is in _Technical Preview_.
112
+
Configuration options and implementation details are subject to change in minor releases without being preceded by deprecation warnings.
113
+
****
114
+
115
+
Some uses cases require tracking the value of a particular field between two jobs.
116
+
Examples include:
117
+
118
+
* avoiding the need to re-process the entire result set of a long query after an unplanned restart
119
+
* grabbing only new data from an index instead of processing the entire set on each job.
120
+
121
+
The Elasticsearch input plugin provides the <<plugins-{type}s-{plugin}-tracking_field>> and <<plugins-{type}s-{plugin}-tracking_field_seed>> options.
122
+
When <<plugins-{type}s-{plugin}-tracking_field>> is set, the plugin records the value of that field for the last document retrieved in a run into
123
+
a file.
124
+
(The file location defaults to <<plugins-{type}s-{plugin}-last_run_metadata_path>>.)
125
+
126
+
You can then inject this value in the query using the placeholder `:last_value`.
127
+
The value will be injected into the query before execution, and then updated after the query completes if new data was found.
128
+
129
+
This feature works best when:
130
+
131
+
* the query sorts by the tracking field,
132
+
* the timestamp field is added by {es}, and
133
+
* the field type has enough resolution so that two events are unlikely to have the same value.
134
+
135
+
Consider using a tracking field whose type is https://www.elastic.co/guide/en/elasticsearch/reference/current/date_nanos.html[date nanoseconds].
136
+
If the tracking field is of this data type, you can use an extra placeholder called `:present` to inject the nano-second based value of "now-30s".
137
+
This placeholder is useful as the right-hand side of a range filter, allowing the collection of
138
+
new data but leaving partially-searchable bulk request data to the next scheduled job.
139
+
140
+
[id="plugins-{type}s-{plugin}-tracking-sample"]
141
+
===== Sample configuration: Track field value across runs
142
+
143
+
This section contains a series of steps to help you set up the "tailing" of data being written to a set of indices, using a date nanosecond field added by an Elasticsearch ingest pipeline and the `tracking_field` capability of this plugin.
144
+
145
+
. Create ingest pipeline that adds Elasticsearch's `_ingest.timestamp` field to the documents as `event.ingested`:
slices => 5 # optional use of slices to speed data processing, should be equal to or less than number of primary shards
221
+
schedule => '* * * * *' # every minute
222
+
schedule_overlap => false # don't accumulate jobs if one takes longer than 1 minute
223
+
}
224
+
}
225
+
226
+
With this sample setup, new documents are indexed into a `test-*` index.
227
+
The next scheduled run:
228
+
229
+
* selects all new documents since the last observed value of the tracking field,
230
+
* uses {ref}/point-in-time-api.html#point-in-time-api[Point in time (PIT)] + {ref}/paginate-search-results.html#search-after[Search after] to paginate through all the data, and
231
+
* updates the value of the field at the end of the pagination.
232
+
106
233
[id="plugins-{type}s-{plugin}-options"]
107
234
==== Elasticsearch Input configuration options
108
235
@@ -126,12 +253,14 @@ Please check out <<plugins-{type}s-{plugin}-obsolete-options>> for details.
The path to store the last observed value of the tracking field, when used.
471
+
By default this file is stored as `<path.data>/plugins/inputs/elasticsearch/<pipeline_id>/last_run_value`.
472
+
473
+
This setting should point to file, not a directory, and Logstash must have read+write access to this file.
474
+
333
475
[id="plugins-{type}s-{plugin}-password"]
334
476
===== `password`
335
477
@@ -410,6 +552,19 @@ for example: "* * * * *" (execute query every minute, on the minute)
410
552
There is no schedule by default. If no schedule is given, then the statement is run
411
553
exactly once.
412
554
555
+
[id="plugins-{type}s-{plugin}-schedule_overlap"]
556
+
===== `schedule_overlap`
557
+
558
+
* Value type is <<boolean,boolean>>
559
+
* Default value is `true`
560
+
561
+
Whether to allow queuing of a scheduled run if a run is occurring.
562
+
While this is ideal for ensuring a new run happens immediately after the previous on finishes if there
563
+
is a lot of work to do, but given the queue is unbounded it may lead to an out of memory over long periods of time
564
+
if the queue grows continuously.
565
+
566
+
When in doubt, set `schedule_overlap` to false (it may become the default value in the future).
567
+
413
568
[id="plugins-{type}s-{plugin}-scroll"]
414
569
===== `scroll`
415
570
@@ -622,6 +777,28 @@ When the `target` is set to a field reference, the `_source` of the hit is place
622
777
This option can be useful to avoid populating unknown fields when a downstream schema such as ECS is enforced.
623
778
It is also possible to target an entry in the event's metadata, which will be available during event processing but not exported to your outputs (e.g., `target \=> "[@metadata][_source]"`).
624
779
780
+
[id="plugins-{type}s-{plugin}-tracking_field"]
781
+
===== `tracking_field`
782
+
783
+
* Value type is <<string,string>>
784
+
* There is no default value for this setting.
785
+
786
+
Which field from the last event of a previous run will be used a cursor value for the following run.
787
+
The value of this field is injected into each query if the query uses the placeholder `:last_value`.
788
+
For the first query after a pipeline is started, the value used is either read from <<plugins-{type}s-{plugin}-last_run_metadata_path>> file,
789
+
or taken from <<plugins-{type}s-{plugin}-tracking_field_seed>> setting.
790
+
791
+
Note: The tracking value is updated after each page is read and at the end of each Point in Time. In case of a crash the last saved value will be used so some duplication of data can occur. For this reason the use of unique document IDs for each event is recommended in the downstream destination.
* Default value is `"1970-01-01T00:00:00.000000000Z"`
798
+
799
+
The starting value for the <<plugins-{type}s-{plugin}-tracking_field>> if there is no <<plugins-{type}s-{plugin}-last_run_metadata_path>> already.
800
+
This field defaults to the nanosecond precision ISO8601 representation of `epoch`, or "1970-01-01T00:00:00.000000000Z", given nano-second precision timestamps are the
801
+
most reliable data format to use for this feature.
0 commit comments