elastic / elasticsearch-js

Official Elasticsearch client library for Node.js
https://ela.st/js-client
Apache License 2.0
29 stars 731 forks source link

putGeoipDatabase without body parameter returns an error #2482

Open SoniaSanzV opened 6 days ago

SoniaSanzV commented 6 days ago

🐛 Bug report

ES js client version: 8.15

When creating an ip_location database with the JS client, it fails for non maxmind database types. This does not happen if we pass the body, which is marked as deprecated.

For example, using ipinfo type as example, this is working as expected:

// Our code:
await clusterClient.asCurrentUser.ingest.putGeoipDatabase({
          id: normalizedDatabaseName,
          body: serializedDatabase,
        });

// That would be, for example:
{ id: 'standard_privacy', body: { name: 'standard_privacy', ipinfo: {} } }

But this is not working unless the type is maxmind.

// Our code:
await clusterClient.asCurrentUser.ingest.putGeoipDatabase({
          id: normalizedDatabaseName,
          name: serializedDatabase.name
        });

// That would be, for example (there is not parameter for the type, in this case `ipinfo`):
 {
  id: 'standard_privacy',
  name: 'standard_privacy'
}

And this is the response that I'm receiving.

{
    "statusCode": 400,
    "error": "Bad Request",
    "message": "Failed to build [database] after last required field arrived",
    "attributes": {
        "error": {
            "root_cause": [
                {
                    "type": "x_content_parse_exception",
                    "reason": "Failed to build [database] after last required field arrived"
                }
            ],
            "type": "x_content_parse_exception",
            "reason": "Failed to build [database] after last required field arrived",
            "caused_by": {
                "type": "illegal_argument_exception",
                "reason": "Exactly one provider object must be specified, but [0] were found"
            }
        },
        "causes": [
            "Exactly one provider object must be specified, but [0] were found"
        ]
    }
}

To reproduce

Create a database with the client using a type but maxmind

await clusterClient.asCurrentUser.ingest.putGeoipDatabase({
          id: 'standard_privacy',
          name: 'standard_privacy'
        });

Expected behavior

I can create a database using the client

Node.js version

20.15.1

@elastic/elasticsearch version

8.15

Operating system

macOs

Any other relevant environment information

No response

JoshMock commented 5 days ago

According to the docs, maxmind is currently the only geolocation provider supported by Elasticsearch:

At present, the only supported provider is maxmind, and the maxmind provider requires that an account_id (string) is configured

This is also an upstream issue with Elasticsearch rather than the JS client. When ES expands support to include other providers, the spec will be updated to ensure all clients support those providers.

ElenaStoeva commented 4 days ago

Hi @JoshMock, the Es documentation says that both maxmind and ipinfo are accepted as providers. Why does the JS client documentation say that only maxmind is supported?