# Execute enrich policy always blocks until complete. Improve documentation or bug?

**URL:** <https://discuss.elastic.co/t/execute-enrich-policy-always-blocks-until-complete-improve-documentation-or-bug/302196>\
**Category:** Elasticsearch\
**Created:** [April 12, 2022, 9:01am UTC](https://discuss.elastic.co/t/execute-enrich-policy-always-blocks-until-complete-improve-documentation-or-bug/302196 "2022-04-12T09:01:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Baard](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/baard/32/104278_2.png) [@Baard](https://discuss.elastic.co/u/Baard)\
**Post date:** [April 12, 2022, 9:01am UTC](https://discuss.elastic.co/t/execute-enrich-policy-always-blocks-until-complete-improve-documentation-or-bug/302196/1 "2022-04-12T09:01:25Z")

</div>

See [execute-enrich-policy-api-query-params wait\_for\_completion](https://www.elastic.co/guide/en/elasticsearch/reference/current/execute-enrich-policy-api.html#execute-enrich-policy-api-query-params)

I am running Elasticsearch version 7.17.2 and this part of the documentation is a bit confusing

```auto
wait_for_completion
    (Required, Boolean) If true, the request blocks other enrich policy execution requests until complete. Defaults to true.

```

When I execute a enrich policy twice in a row with wait\_for\_completion=false I expected that the second invocation would not block according to this documentation. However, the second invocation returns a status 429 - too many requests. I assume that the request is "blocked" when I receive that status. Is this a bug or is it just the documentation that needs a update? Why is not the obvious effect better documented, that is that the request returns before the task is completed with a taskid when wait\_for\_completion=false?

```auto
PUT /_enrich/policy/my-policy/_execute?wait_for_completion=false

```

The only difference seems to be that wait\_for\_completion=false returns before it is completed with a taskid while wait\_for\_completion=true returns a response when it has been completed (unless there is an error ofc).

There is also no documentation of the different type of responses that is returned

```auto
PUT /_enrich/policy/my-policy/_execute?wait_for_completion=false

```

returns before task is completed a taskid

```auto
{
  "task" : "-q20J8U_SGOFg0d4CFXceg:39550"
}

```

```auto
PUT /_enrich/policy/my-policy/_execute?wait_for_completion=true

```

returns

```auto
{
  "status" : {
    "phase" : "COMPLETE"
  }
}

```

How to produce a "block" or 429 response  
Do a

```auto
PUT /_enrich/policy/my-policy/_execute?wait_for_completion=false

```

then immediately follow up with

```auto
PUT /_enrich/policy/my-policy/_execute?wait_for_completion=true

```

or

```auto
PUT /_enrich/policy/my-policy/_execute?wait_for_completion=false

```

to get the response

```auto
{
  "error" : {
    "root_cause" : [
      {
        "type" : "es_rejected_execution_exception",
        "reason" : "Could not obtain lock because policy execution for [my-policy] is already in progress."
      }
    ],
    "type" : "es_rejected_execution_exception",
    "reason" : "Could not obtain lock because policy execution for [my-policy] is already in progress."
  },
  "status" : 429
}

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 10, 2022, 9:01am UTC](https://discuss.elastic.co/t/execute-enrich-policy-always-blocks-until-complete-improve-documentation-or-bug/302196/2 "2022-05-10T09:01:35Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
