Python Driver and Elastic Docs Parity

Hi,

I work with the python driver fairly often and love it. One challenge is documentation.

After the v8 release there have been some challenges.

One example is with request body requirements differing between the driver and in the dev console. As an example, the request body in documentation here works in dev console, but stack traces in code.

The python docs have some description fields missing, which adds to the challenge:

>>> pol = {
...     "policy": {
...         "phases": {
...             "warm": {"min_age": "7d", "actions": {"set_priority": {"priority": 50}}},
...             "hot": {"min_age": "0ms", "actions": {"set_priority": {"priority": 100}}}
...         }
...     }
... }
>>> ilm_client.put_lifecycle(name=_ALERT_ILM_POLICY_NAME, policy=pol)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/patrick/ps-elk/venv/lib/python3.8/site-packages/elasticsearch/_sync/client/utils.py", line 414, in wrapped
    return api(*args, **kwargs)
  File "/Users/patrick/ps-elk/venv/lib/python3.8/site-packages/elasticsearch/_sync/client/ilm.py", line 375, in put_lifecycle
    return self.perform_request(  # type: ignore[return-value]
  File "/Users/patrick/ps-elk/venv/lib/python3.8/site-packages/elasticsearch/_sync/client/_base.py", line 390, in perform_request
    return self._client.perform_request(
  File "/Users/patrick/ps-elk/venv/lib/python3.8/site-packages/elasticsearch/_sync/client/_base.py", line 321, in perform_request
    raise HTTP_EXCEPTIONS.get(meta.status, ApiError)(
elasticsearch.BadRequestError: BadRequestError(400, 'x_content_parse_exception', '[1:12] [lifecycle_policy] unknown field [policy]')

The same request without the policy key works:

>>> new_policy
{'phases': {'warm': {'min_age': '7d', 'actions': {'set_priority': {'priority': 50}}}, 'hot': {'min_age': '0ms', 'actions': {'set_priority': {'priority': 100}}}}}
>>> ilm_client.put_lifecycle(name=_ALERT_ILM_POLICY_NAME, policy=new_policy)
ObjectApiResponse({'acknowledged': True})

I made this post to:

  1. Bring this to Elastic team's attention
  2. Ask: is there supposed to be parity between dev console and python driver? Or is this an example of a broader pattern with the v8 driver

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