-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Actions] ES Index action should be able to iterate over context variables #89430
Comments
Pinging @elastic/kibana-alerting-services (Team:Alerting Services) |
Is the problem here that you can't use mustache sections at all? Which I don't think you can, because the That thought is referenced in issue comment, and I believe is spot-on correct: #78877 (comment) - we need to change the So, these are kinda DUPs, but I think the referenced issue is kinda noisy and there's a lot in there about how to make JSON validation work still work in the UI (which seems pretty much impossible, once you throw in mustache sections for looping). Perhaps we should re-target this one to just get the type of the |
The kibana/x-pack/plugins/actions/server/builtin_action_types/es_index.ts Lines 38 to 40 in 1ab03d0
I believe the issue is with the UI editor validating for JSON objects only so if you try something like
it gives you a validation error. The linked comment makes it seem like a more complicated issue though so it sounds like I'm missing something :) |
Yeah, sorry, it's kinda confusing. es index spec's it's kibana/x-pack/plugins/actions/server/builtin_action_types/es_index.ts Lines 38 to 40 in 7609fb9
webhook spec's it's kibana/x-pack/plugins/actions/server/builtin_action_types/webhook.ts Lines 70 to 72 in 7609fb9
They are both intended to be JSON (actually, webhook body could be XML, plain text, etc - part of the reason we didn't spec it as a JSON-able object). The string version seems like what we should have done with es index, because there's no way to represent mustache templates with "sections" (eg, for looping) as JSON. As a string though, sure! a bit more background: The further complication is ... how do we validate this mustache-infused JSON as JSON - particularly in the UX. I suspect we can't. There are other things you can't do like use an "unquoted" mustache variable, which would work perfectly fine at runtime (hehe - even GH marks the double-braced variable reference as an error!): {
"foo": {{context.variable-that-is-a-number}}
} There are probably a lot of cases where a customer wouldn't use mustache sections, or need to use unquoted mustache variables like above, that could end up validating as valid JSON, so there are cases where the validation is useful. Not sure what the answer to this "what do we do about UX validation for these" might be. Allow validation by default, but let the user turn it off if it gets annoying (eg w/ a checkbox)? Just stop validating in the UX altogether? Hope we could figure out some way of actually doing validation with the mustache Presumably we'd always be doing runtime validation on such strings, once rendered into their final form via the mustache rendering, but that's obviously later than we'd want - when the action is actually executed. I suspect that's where we'll end up though, in terms of the only place that's safe to validate the In any case, we can't ever do things like mustache sections with es index |
Gotcha. Thanks for the explanation! |
Having written all that, I'm not sure we have an explicit issue open to migrate the I'm not seeing an issue, maybe @mikecote remembers one? If we don't already have one, perhaps we could treat this issue as a meta of how to get this fixed, which would be
|
I see this is quite an old thread, but this functionality would be very useful if there is a way around the validation issue. |
The ES Index action currently asks users to create a single document to index each time the action runs. This action can incorporate context variables using mustache templating. It would be useful to allow the Index action to use mustache templating to iterate over a context variable that is an array and specify a document to index for each element of that array.
This was discussed specifically as part of the action handling for the search alert when the hits are passed as an action variable. If we have 1,000 hits for an execution of this alert, we should be able to bulk index 1,000 documents with a single ES index action.
As a reference, other connectors, like the slack connector, can do something like this:
The text was updated successfully, but these errors were encountered: