-
Notifications
You must be signed in to change notification settings - Fork 5k
[DOCS] Add new topic about data deduplication #15171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
fea94e5
[DOCS] Add new topic about data deduplication
dedemorton 6748be5
More updates
dedemorton 1c6f94d
Corrections from testing
dedemorton 9e2f14e
Add more changes from the review
dedemorton 04af9dc
Add more fixes from the review
dedemorton 407a691
Fix typo in processor name
dedemorton cf4fe6d
Update notice
dedemorton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| [id="{beatname_lc}-deduplication"] | ||
| == Data deduplication | ||
|
|
||
| The {beats} framework guarantees at-least-once delivery to ensure that no data | ||
| is lost when events are sent to outputs that support acknowledgement, such as | ||
| {es}, {ls}, Kafka, and Redis. This is great if everything goes as planned. But | ||
| if {beatname_uc} shuts down during processing, or the connection is lost before | ||
| events are acknowledged, you can end up with duplicate data. | ||
|
|
||
| [float] | ||
| === What causes duplicates in {es}? | ||
|
|
||
| When an output is blocked, the retry mechanism in {beatname_uc} attempts to | ||
| resend events until they are acknowledged by the output. If the output receives | ||
| the events, but is unable to acknowledge them, the data might be sent to the | ||
| output multiple times. Because document IDs are typically set by {es} _after_ it | ||
| receives the data from {beats}, the duplicate events are indexed as new | ||
| documents. | ||
|
|
||
| [float] | ||
| === How can I avoid duplicates? | ||
|
|
||
| Rather than allowing {es} to set the document ID, set the ID in {beats}. The ID | ||
| is stored in the {beats} `@metadata._id` field and used to set the document ID | ||
| during indexing. That way, if {beats} sends the same event to {es} more than | ||
| once, {es} overwrites the existing document rather than creating a new one. | ||
|
|
||
| The `@metadata._id` field is passed along with the event so that you can use | ||
| it to set the document ID after the event has been published by {beatname_uc} | ||
| but before it's received by {es}. For example, see <<ls-doc-id>>. | ||
|
|
||
| There are several ways to set the document ID in {beats}: | ||
|
|
||
| * *`add_id` processor* | ||
| + | ||
| Use the <<add-id,`add_id`>> processor when your data has no natural key field, | ||
| and you can’t derive a unique key from existing fields. | ||
| + | ||
| This example generates a unique ID for each event and adds it to the | ||
| `@metadata._id` field: | ||
| + | ||
| [source,yaml] | ||
| ---- | ||
| processors: | ||
| - add_id: ~ | ||
| ---- | ||
|
|
||
| * *`fingerprint` processor* | ||
| + | ||
| Use the <<fingerprint,`fingerprint`>> processor to derive a unique key from | ||
| one or more existing fields. | ||
| + | ||
| This example uses the values of `field1` and `field2` to derive a unique key | ||
| that it adds to the `@metadata._id` field: | ||
| + | ||
| [source,yaml] | ||
| ---- | ||
| processors: | ||
| - fingerprint: | ||
| fields: ["field1", "field2"] | ||
| target_field: "@metadata._id" | ||
| ---- | ||
|
|
||
| * *`decode_json_fields` processor* | ||
| + | ||
| Use the `document_id` setting in the <<decode-json-fields,`decode_json_fields`>> | ||
| processor when you're decoding a JSON string that contains a natural key field. | ||
| + | ||
| For this example, assume that the `message` field contains the JSON string | ||
| `{"myid": "100", "text": "Some text"}`. This example takes the value of `myid` | ||
| from the JSON string and stores it in the `@metadata._id` field: | ||
| + | ||
| [source,yaml] | ||
| ---- | ||
| processors: | ||
| - decode_json_fields: | ||
| document_id: "myid" | ||
| fields: ["message"] | ||
| max_depth: 1 | ||
| target: "" | ||
| ---- | ||
| + | ||
| The resulting document ID is `100`. | ||
|
|
||
| * *JSON input settings* | ||
| + | ||
| Use the `json.document_id` input setting if you’re ingesting JSON-formatted | ||
| data, and the data has a natural key field. | ||
| + | ||
| This example takes the value of `key1` from the JSON document and stores it in | ||
| the `@metadata._id` field: | ||
| + | ||
| [source,yaml] | ||
| ---- | ||
| filebeat.inputs: | ||
| - type: log | ||
| paths: | ||
| - /path/to/json.log | ||
| json.document_id: "key1" | ||
| ---- | ||
|
|
||
| [float] | ||
| [[ls-doc-id]] | ||
| === {ls} pipeline example | ||
|
|
||
| For this example, assume that you've used one of the approaches described | ||
| earlier to store the document ID in the {beats} `@metadata._id` field. To | ||
| preserve the ID when you send {beats} data through {ls} en route to {es}, | ||
| set the `document_id` field in the {ls} pipeline: | ||
|
|
||
| [source,json] | ||
| ---- | ||
| input { | ||
| beats { | ||
| port => 5044 | ||
| } | ||
| }} | ||
|
|
||
| output { | ||
| if [@metadata][_id] { | ||
| elasticsearch { | ||
| hosts => ["http://localhost:9200"] | ||
| document_id => "%{[@metadata][_id]}" <1> | ||
| index => "%{[@metadata][beat]}-%{[@metadata][version]}" | ||
| } | ||
| } else { | ||
| elasticsearch { | ||
| hosts => ["http://localhost:9200"] | ||
| index => "%{[@metadata][beat]}-%{[@metadata][version]}" | ||
| } | ||
| } | ||
| } | ||
| ---- | ||
| <1> Sets the `document_id` field in the | ||
| {logstash-ref}/plugins-outputs-elasticsearch.html[{es} output] to the value | ||
| stored in `@metadata._id`. | ||
|
|
||
| When {es} indexes the document, it sets the document ID to the specified value, | ||
| preserving the ID passed from {beats}. | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.