Incorrect HTTP method for uri

Hello,

I want to connect using the python client but I can't figure out what's wrong.

from elasticsearch import Elasticsearch

endpoint = 'https://foo.gcp.cloud.es.io:443/search-addresses/_doc?pipeline=ent-search-generic-ingestion'
api_key = "bar"
api_id = "1568085128"

es_client = Elasticsearch(
    endpoint,
    api_key=(api_id, api_key),
    )

print(es_client.info())
es_client.info()

What's the issue? I literally don't understand it. I use the endpoint given to me, I use the api key given to me, I use the python client given to me - why would I get an HTTP request error?

Because that is not the base endpoint.

That's an endpoint to actually ingest document and call an ingest pipeline not to just initiate a client connection.

The endpoint is just
https://foo.gcp.cloud.es.io:443

Perhaps try that... and make sure you get the correct endpoint as there is an es. and kb. for elasticsearch and kibana respectively

https://mydeployment.es.us-west1.gcp.cloud.es.io
.....................^^

Note: I do think it is important to put the port :443 on the end because some of the clients if a port is not specified it will add :9200 which is the default elasticsearch port ... but not for Elastic Cloud because of HTTPs

And you can always get the endpoint from the cloud console

Thanks, I don't think I've ever seen what you show in the screenshot though. I'll give it another try.

That's from the elastic cloud console where you set up your elastic cloud account and the elastic cloud deployments.

Long story short, it's just a base URL plus 443 that reste of That stuff is actually part of a different API call

Ok so I tried it and I simply can't get it working. I'm so buffled that there isn't simply a straight forward explanation.

  1. Are my parameters for the Elastrichsearch() correct?
  2. I use the gcp.cloud.es.io:443 endpoint, correct?
  3. I Create a new API key. The value is the actualy key but what is the id? I tried both, the name and the user.

I still get 401. I really really don't understand the issue. Why can't I simply connect by API key like you'd do it when using curl?

Take a look at this ...

OK I just tested this and all works as expected.

POST /_security/api_key
{
  "name": "my-discuss-api-key",
  "expiration": "1d",   
  "role_descriptors": { 
    "role-a": {
      "cluster": ["all"]
      
    }
  }
}
# Result
{
  "id": "sadfasdfGGJCaJCcrUTy",
  "name": "my-discuss-api-key",
  "expiration": 1670861752818,
  "api_key": "asfdasdf9YOve4r3g",
  "encoded": "cXlINEFZVUJHR0pDYUpDY3JVVHk6Q3JEeTNfbC1SdHVEMzlZT3ZlNHIzZw=="
}

Both Options Work

from elasticsearch import Elasticsearch

es = Elasticsearch(
	  "https://my-demo-cluster.es.us-west1.gcp.cloud.es.io:443",
    api_key=("sadfasdfGGJCaJCcrUTy", "asfdasdf9YOve4r3g"),
)

# es = Elasticsearch(
#     cloud_id="my-demo-cluster:asdfsadfasdfkLmVzLmlvJDA1M2Y1MWYwMDViOTRjNDA4NGMzNmNiM2JkNzRjNDY3JGIxZTUyOWEwNTBkNjRkODZhMzIxZTBhMjU3YjRlODhh",
#     api_key=("sadfasdfGGJCaJCcrUTy", "asfdasdf9YOve4r3g"),
# )


output = es.info(),

print(output, end=" ")

(ObjectApiResponse({'name': 'instance-0000000095', 'cluster_name': 'sadfsadf4c4084c36cb3bd74c467', 'cluster_uuid': 'sadfsadfa-k2eXlBQ', 'version': {'number': '8.5.3', 'build_flavor': 'default', 'build_type': 'docker', 'build_hash': '4ed5ee9afac63de92ec98f404ccbed7d3ba9584e', 'build_date': '2022-12-05T18:22:22.226119656Z', 'build_snapshot': False, 'lucene_version': '9.4.2', 'minimum_wire_compatibility_version': '7.17.0', 'minimum_index_compatibility_version': '7.0.0'}, 'tagline': 'You Know, for Search'}),)

Exactly what error are you getting. when you state it is not working you have to show the exact code and the error messages otherwise we are just guessing.

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