Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] When calling Opensearch Bulk API, host and port are called in a non-combined form. #824

Open
fast-coding opened this issue Sep 20, 2024 · 0 comments
Labels
bug Something isn't working untriaged Need triage

Comments

@fast-coding
Copy link

fast-coding commented Sep 20, 2024

What is the bug?

As stated in the official document, errors occur in host and port when creating the Client.
https://opensearch.org/docs/latest/clients/python-low-level/

client = OpenSearch(
    hosts = [{'host': host, 'port': 443}],

How can one reproduce the bug?

import boto3
from requests_aws4auth import AWS4Auth
from opensearchpy import OpenSearch, RequestsHttpConnection, AWSV4SignerAuth

host = '<opensearch_domain>/_bulk'
region = 'ap-northeast-2'  
service = 'es'
credentials = boto3.Session().get_credentials()
awsauth = AWSV4SignerAuth(credentials, region, service)

index = 'movies'
datatype = '_doc'

client = OpenSearch(
    # hosts=[{"host": host, "port": 9200}],
    hosts=[host+"9200"],
    http_auth=awsauth,
    use_ssl=True,
    verify_certs=True,
    connection_class = RequestsHttpConnection,
    pool_maxsize = 20
)
movies = '{ "index" : { "_index" : "movies", "_id" : "2" } } \n { "title" : "Interstellar", "director" : "Christopher Nolan", "year" : "2014"} \n { "create" : { "_index" : "movies", "_id" : "3" } } \n { "title" : "Star Trek Beyond", "director" : "Justin Lin", "year" : "2015"} \n { "update" : {"_id" : "3", "_index" : "movies" } } \n { "doc" : {"year" : "2016"} }'

client.bulk(movies)

Error

requests.exceptions.InvalidURL: Failed to parse: https://[<opensearch_domain>/_bulk]:9200/_bulk

What is the expected behavior?

I re-set the host in the following format and it works normally.

client = OpenSearch(
    hosts=[host+"9200"],
    http_auth=awsauth,

Do you have any additional context?

In summary, it seems that when i create the Opensearch client, i need to create the host and port as a string and then put it in the list.
However, the official document says that i need to save it in dictionary form in the list. Please check this part to fix the bug.

@fast-coding fast-coding added bug Something isn't working untriaged Need triage labels Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working untriaged Need triage
Projects
None yet
Development

No branches or pull requests

1 participant