def _compat_field_caps()

in eland/field_mappings.py [0:0]


def _compat_field_caps(client, fields, index=None):
    """The field_caps API moved it's 'fields' parameter to the HTTP request body
    in Elasticsearch 8.5.0 (previously was only accepted in the query string).
    This can cause some unfortunate errors for users of Eland against old server
    versions because at that point the version of the Elasticsearch client actually
    matters for compatibility, which can be unexpected by consumers of *only* Eland.

    Our work-around below is to force the parameter in the query string on older server versions.
    """

    # If the server version is 8.5.0 or later we don't need
    # the query string work-around. Sending via any client
    # version should be just fine.
    try:
        elastic_version = es_version(client)
    # If we lack sufficient permission to determine the Elasticsearch version,
    # to be sure we use the workaround for versions smaller than 8.5.0
    except elasticsearch.AuthorizationException as e:
        raise RuntimeWarning(
            "Couldn't determine Elasticsearch host's version. "
            "Probably missing monitor/main permissions. "
            "Continuing with the query string work-around. "
            "Original exception: " + repr(e)
        )
        elastic_version = None
    if elastic_version and elastic_version >= (8, 5, 0):
        return client.field_caps(index=index, fields=fields)

    # Otherwise we need to force sending via the query string.
    from elasticsearch._sync.client import SKIP_IN_PATH, _quote

    if index not in SKIP_IN_PATH:
        __path = f"/{_quote(index)}/_field_caps"
    else:
        __path = "/_field_caps"
    __query: Dict[str, Any] = {}
    if fields is not None:
        __query["fields"] = fields
    return client.perform_request(
        "POST", __path, params=__query, headers={"accept": "application/json"}
    )