Skip to content

Ingest pipeline best practices #1381

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

Open
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

philippkahr
Copy link
Contributor

@philippkahr philippkahr commented May 7, 2025

based on the discussions here: #1052

this is my first PR against the docs, and I am building a couple of new pages. I think it makes sense to split it out. I am putting it into that part of the docs. https://www.elastic.co/docs/manage-data/ingest/transform-enrich/ingest-pipelines The tips and tricks are generic and not specific to just o11y, or security.

image

@philippkahr
Copy link
Contributor Author

philippkahr commented May 7, 2025

There are a couple of things I need help with.

  • Can someone proof read it and give suggestion on the ease of understanding.
  • Does the file order make sense in the way I put it? Should we do an additional subfolder?
  • Can you read through it please and here and there I think we can add links to different docs, like when I say remove. processor, we should link to the remove processor probably?
  • Not a 100% convincend that common mistakes is the correct heading

@philippkahr philippkahr added Team:Platform Issues owned by the Platform Docs Team documentation Improvements or additions to documentation enhancement New feature or request labels May 7, 2025
@kilfoyle kilfoyle added Team:Obs Issues owned by the Observability Docs Team and removed Team:Platform Issues owned by the Platform Docs Team labels May 7, 2025
@kilfoyle
Copy link
Contributor

kilfoyle commented May 7, 2025

Thanks a lot for opening this Philipp! I've added the "Team:Obs" label since under the new docs organization that's where the ingest content will land.

@philippkahr philippkahr requested review from a team as code owners May 22, 2025 08:29
@colleenmcginnis colleenmcginnis added the Team:Ingest Issues owned by the Ingest Docs Team label May 27, 2025
@alexandra5000 alexandra5000 self-assigned this May 28, 2025
Copy link
Contributor

@colleenmcginnis colleenmcginnis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@philippkahr I started reviewing this PR, but I didn't get very far (yet!). There's a lot of content to get into! I'm just going to post the comments/questions/suggestions I have so far so I can see if I'm on the right track. I can jump back in next week.

Some themes in my early feedback include:

  • I see some opportunities to simplify the examples to really emphasize the point you're making in each section.
  • It might be helpful to write out in plain language what the example is trying to achieve before jumping into a code snippet. (I provided a couple suggestions below.)
  • There are probably opportunities to remove redundant information.

Comment on lines 56 to 79
### Contains operation and null check

This includes an initial null check, which is not necessary.

```painless
"if": "ctx.event?.action !=null
&& ['bandwidth','spoofed syn flood prevention','dns authentication','tls attack prevention',
'tcp syn flood detection','tcp connection limiting','http rate limiting',
'block malformed dns traffic','tcp connection reset','udp flood detection',
'dns rate limiting','malformed http filtering','icmp flood detection',
'dns nxdomain rate limiting','invalid packets'].contains(ctx.event.action)"
```

This behaves nearly the same:

```painless
"if": "['bandwidth','spoofed syn flood prevention','dns authentication','tls attack prevention',
'tcp syn flood detection','tcp connection limiting','http rate limiting',
'block malformed dns traffic','tcp connection reset','udp flood detection',
'dns rate limiting','malformed http filtering','icmp flood detection',
'dns nxdomain rate limiting','invalid packets'].contains(ctx.event?.action)"
```

The difference is in the execution itself which should not matter since it is Java under the hood and pretty fast as this. In reality what happens is the following when doing the first one with the initial: `ctx.event?.action != null` If action is null, then it will exit here and not even perform the contains operation. In our second example we basically run the contains operation x times, for every item in the array and have `valueOfarray.contains('null')` then.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example confuses me. Why would you want to run the contains operation n times if you already know ctx.event.action is null and it's going to return false.

@colleenmcginnis
Copy link
Contributor

☝️ Updating with the latest on main to hopefully get rid of all the hints here.

@eedugon
Copy link
Contributor

eedugon commented Jun 13, 2025

Cross linking with #1727, so we can ensure the new docs complement each other properly.

}
}
],
"on_failure": [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to ignore, but IME when users want global error handling they also want to reroute documents to a different failure index which might be nice to include.


There are various ways to handle data in ingest pipelines, and while they all produce similar results, some methods might be more suitable depending on the specific case. This section provides guidance to ensure that your ingest pipelines are consistent, readable, and maintainable. While we won't focus heavily on performance optimizations, the goal is to create pipelines that are easy to understand and manage.

## Accessing Fields in `if` Statements
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"if statements" are officially called conditionals

AND I'd like to request this be flushed out to include context:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@colleenmcginnis can you help me cross link this page https://github.com/elastic/docs-content/pull/1381/files#diff-a70e1482d1c5914e741755809833f482be84ef173010439dae33fb194fd57a55 the error-handling one then here ? I added a bit of fluff around it.


```painless
if (ctx.user_name != null) {
ctx.user.name = ctx.user_name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

per above this if will error if field doesn't exist (vs check is field exists but its value is NULL)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don#t fully get it. Because this:

POST _ingest/pipeline/_simulate
{
  "docs": [
  {
    "_source": {
      "user_name": ""
      }
  },
  {
    "_source": {
      "user_name": "abc"
      }
  },
  {
    "_source": {
    }
  }],
  "pipeline": {
    "processors": [
      {
        "script": {
          "source": "
            ctx.user = new HashMap();
            ctx.user.name = ctx.user_name;
              
          "
        }
      }
    ]
  }
}

works as expected, the value of user.name is then actually: null. Or am I missing something?

Copy link

github-actions bot commented Jun 13, 2025

🔍 Preview links for changed docs:

🔔 The preview site may take up to 3 minutes to finish building. These links will become live once it completes.

…-pipelines

Suggested copy edits for `manage-data/ingest/transform-enrich/common-mistakes.md`
Copy link
Contributor

@colleenmcginnis colleenmcginnis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments on the remaining pages, manage-data/ingest/transform-enrich/error-handling.md and manage-data/ingest/transform-enrich/general-tips.md.


Ingest pipelines in Elasticsearch are powerful tools for transforming and enriching data before indexing. However, errors can occur during processing. This guide outlines strategies for handling such errors effectively.

**Important**: Ingest pipelines are executed before the document is indexed by Elasticsearch. You can handle the errors occurring while processing the document (i.e. transforming the json object) but not the errors triggered while indexing like mapping conflict. For this is the Elasticsearch Failure Store.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**Important**: Ingest pipelines are executed before the document is indexed by Elasticsearch. You can handle the errors occurring while processing the document (i.e. transforming the json object) but not the errors triggered while indexing like mapping conflict. For this is the Elasticsearch Failure Store.
:::{important}
Ingest pipelines are executed before the document is indexed by Elasticsearch. You can handle the errors occurring while processing the document (i.e. transforming the json object) but not the errors triggered while indexing like mapping conflict. For this is the Elasticsearch Failure Store.
:::

- Parsing Errors: Occur when a processor fails to parse a field, such as a date or number.
- Missing Fields: Happen when a required field is absent in the document.

:::tip
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should fix the rendering issue (seen here).

Suggested change
:::tip
:::{tip}


The `on_failure` parameter can be defined either for individual processors or at the pipeline level to catch exceptions that may occur during document processing. The `ignore_failure` option allows a specific processor to silently skip errors without affecting the rest of the pipeline.

## Global vs. Processor-Specific
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## Global vs. Processor-Specific
## Global vs. processor-specific


We can restructure the pipeline by moving the `on_failure` handling directly into the processor itself. This allows the pipeline to continue execution. In this case, the `event.category` processor still runs. You can also retain the global `on_failure` to handle errors from other processors, while adding processor-specific error handling where needed.

(While executing two `set` processors within the `dissect` error handler may not always be ideal, it serves as a demonstration.)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use a note here instead of a paragraph in parentheses?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file needs to be significantly edited down. There's a lot of overlap with the content in the Create readable and maintainable ingest pipelines page (manage-data/ingest/transform-enrich/common-mistakes.md). We should avoid duplication to avoid confusion among users and make the docs easier to maintain. Let me know if you'd like me to take a pass at de-duplicating this content.

serverless: ga
---

# Tips and Tricks
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not really a fan of this as a title for technical documentation, but I can't think of a good alternative at the moment. 🙃


There are various ways to handle data in ingest pipelines, and while they all produce similar results, some methods might be more suitable depending on the specific case. This section provides guidance to ensure that your ingest pipelines are consistent, readable, and maintainable. While we won't focus heavily on performance optimizations, the goal is to create pipelines that are easy to understand and manage.

## Accessing fields in `if` statements / conditionals
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section seems to duplicate information from the Create readable and maintainable ingest pipelines page. Do we need this information in two places?


This works fine, as you now check for null.

However there is also an easier to write and maintain alternative available:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also feels like it's aligned with the content in Create readable and maintainable ingest pipelines. Could we integrate this information into that file using the format established there?


## Remove empty fields or remove empty fields that match a regular expression

Alex and Honza created a [blog post](https://alexmarquardt.com/2020/11/06/using-elasticsearch-painless-scripting-to-iterate-through-fields/) presenting painless scripts that remove empty fields or fields that match a regular expression. We are already using this in a lot of places. Most of the time in the custom pipeline and in the final pipeline as well.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should rely on a link to an external blog post in the official documentation. We don't have control over whether that information will continue to be available and will be kept up to date.

}
```

## Check if a value exists and is not null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, this feels like it's duplicating a lot of the same information in the Create readable and maintainable ingest pipelines page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request Team:Ingest Issues owned by the Ingest Docs Team Team:Obs Issues owned by the Observability Docs Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants