Skip to content

Adds an operator to create enrich policies#2045

Merged
gareth-ellis merged 3 commits into
elastic:masterfrom
slDias:enrich-1796
May 8, 2026
Merged

Adds an operator to create enrich policies#2045
gareth-ellis merged 3 commits into
elastic:masterfrom
slDias:enrich-1796

Conversation

@slDias
Copy link
Copy Markdown
Contributor

@slDias slDias commented Feb 26, 2026

As suggested in Issue #1796, this commit adds a new operator that combines the delete, creation and execution of enrich policies within a single operation.

I've added a new challenge to nyc_taxis track to test this it is equivalent to the esql challenge, it can be found here (I can also open a MR replacing the 'esql' one, if desired).

Happy to change anything if needed.

@gareth-ellis gareth-ellis requested review from a team and craigtaverner March 4, 2026 14:18
@slDias slDias force-pushed the enrich-1796 branch 2 times, most recently from b6bdff7 to 69b48e4 Compare March 5, 2026 11:27
Copy link
Copy Markdown

@craigtaverner craigtaverner left a comment

Choose a reason for hiding this comment

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

This looks like a nice addition. But there are a few things to fix or change. At the very least fix the docs. The suggestions I made for supporting more flexible combinations of the delete/create/execute actions could be done here or in a followup PR.

Comment thread docs/track.rst Outdated
Properties
""""""""""

Meta-data
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This meta-data section seems to have been incorrectly placed inside the esql section, instead of the create-enrich-policy section below.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for reviewing it. The docs were mixed during a merge, I've rebased the changes instead so its fixed now.

Comment thread docs/track.rst Outdated
Properties
""""""""""

It's properties follows the request body of the `Create an enrich policy API <https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-enrich-put-policy>`_
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This link should rather be moved into the policies list item below.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

Comment thread docs/track.rst Outdated
{
"name": "create-enrich-policy",
"operation": {
"operation-type": "create-enrich-policy",
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since the operation does more than just create, I think it should be named enrich-policy, and it can delete, create and execute the policy (or any combination of those actions).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

renamed it, the combinations will be part of another PR

Comment thread docs/track.rst Outdated
}
}
},
"delete": true
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Shouldn't the flag be inside the operation? Having it outside the operation makes it seem like it is not tied to enrich policy management at all, but part of generic challenges.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed, good catch. it was already part of the operation but I've misplace it in the docs.

Comment thread esrally/driver/runner.py Outdated
return "run-until"


class CreateEnrichPolicy(Runner):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since this can do much more than just create the policy, I think it should be renamed EnrichPolicy, and take optional boolean flags for delete, create and execute, and only create requires the policy bodies, while all the rest require at least the policy name.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Renamed it for now, I'll work on a separate PR for the new format.
I gave it some thought, wdyt of removing policies and then having lists on the delete and execute? that gives more control over what is done to each policy.

example:

{
  "operation-type": "enrich-policy",
  "delete": [
    "a-policy-name",
    "another-policy",
    "yet-another-one"
  ],
  "create": {
    "a-policy-name": {
      "match": {
        "indices": "nyc_rate_codes",
        "match_field": "id",
        "enrich_fields": [
          "name"
        ]
      }
    }
  },
  "execute": [
    "a-policy-name",
    "a-completely-different-policy"
  ]
}

I will work on this version if I find the time, since it's easy to change to your suggestion if you prefer later

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Got to implement this, it's as a draft in case you decide it's no good, but it is working and ready to review: #2101

Comment thread docs/track.rst
"name": "create-enrich-policy",
"operation": {
"operation-type": "create-enrich-policy",
"policies": {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I wonder if it would be nicer to have a list instead of an object as the value of policies. Then we could, for example, just list the names if all we want to do it re-execute existing policies:

{
  "name": "re-execute-enrich-policies",
  "operation": {
    "operation-type": "enrich-policy",
    "policies": [ "nyc_rate_codes", "nyc_payment_types" ],
    "delete": false,
    "create": false,
    "execute": true
  }
}

If we have "create": true(which can be the default), then the values inside the list of policies must be objects with a single key, the name of the policy, and it's value would be the policy body. This is one level nesting deeper than your example.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

will do that or my suggestion in another PR

Comment thread esrally/driver/runner.py
async def __call__(self, es, params):
enrich_policies = mandatory(params, "policies", self)

if params.get("delete", True):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think it would be nicer to have three booleans: delete, create, execute. The defaults could be: false, true, true.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

will do that or my suggestion in another PR

Comment thread esrally/driver/runner.py
self.logger.debug("Executed %s enrich policies: %s", len(res), [r.body for r in res])

async def __call__(self, es, params):
enrich_policies = mandatory(params, "policies", self)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If we supported the nested arrays approach I described above, we could have a normalize option here to bring the multiple formats into a single version so the functions below do not need to care about that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

will do that or my suggestion in another PR

Comment thread .gitignore Outdated
/.project
/.pydevproject
/.vscode
/.zed
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What does this mean? Should this be in this PR?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this is a folder to be ignored from the zed IDE, which I use. I've removed it to avoid friction

@gareth-ellis
Copy link
Copy Markdown
Member

@slDias let us know if you have any questions regarding @craigtaverner 's review. I'm going to change this to draft, please switch back to "ready for review" when you have addressed the feedback - thanks!

@gareth-ellis gareth-ellis marked this pull request as draft April 8, 2026 13:16
As suggested in Issue elastic#1796, this commit adds a new operator that combines the delete, creation and execution of enrich policies within a single operation.
@slDias slDias force-pushed the enrich-1796 branch 2 times, most recently from bc1f5f1 to 88c5eec Compare April 12, 2026 11:10
@slDias slDias marked this pull request as ready for review April 12, 2026 11:42
slDias added a commit to slDias/rally-fork that referenced this pull request Apr 12, 2026
As discussed in MR elastic#2045, this commit makes it possible to execute different enrichment policies operation separately in the enrich-policy runner.
Copy link
Copy Markdown

@craigtaverner craigtaverner left a comment

Choose a reason for hiding this comment

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

LGTM

@gareth-ellis
Copy link
Copy Markdown
Member

@elasticmachine update branch

@gareth-ellis gareth-ellis merged commit 59de302 into elastic:master May 8, 2026
15 checks passed
@gareth-ellis
Copy link
Copy Markdown
Member

Thanks @slDias !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants