Skip to content

Conversation

@vruello
Copy link
Contributor

@vruello vruello commented Apr 17, 2025

Currently, the path_prefix configuration (i.e. the url path) of the ES host is removed by the httpx client. This PR adds it.

path_prefix is set by client_utils.url_to_node_config (https://github.com/elastic/elastic-transport-python/blob/main/elastic_transport/client_utils.py#L187). It is either "" if the url path is empty or "/", or the url path itself.

For example, if you configure host to be http://localhost:9092/test and run a search() query, you'll see an HTTP request sent to http://localhost:9092/_search, without the "test" prefix.

This is very useful when elastic endpoints are behind a reverse proxy with a specific path.

@cla-checker-service
Copy link

cla-checker-service bot commented Apr 17, 2025

💚 CLA has been signed

@pquentin
Copy link
Member

Thank you! Can you please sign the CLA?

@vruello
Copy link
Contributor Author

vruello commented Apr 30, 2025

Hi! Sorry for the delay. I just signed the CLA.

@vruello
Copy link
Contributor Author

vruello commented Apr 30, 2025

By the way, do you think this commit could be backported to 8.x?

@flonkler
Copy link

flonkler commented Dec 8, 2025

I fixed it by setting base_url=self.base_url, reusing the property that is already implemented in the BaseNode class. Arguably a more "elegant" solution, but it does the same as the implementation in this PR.

Sadly, this PR was inactive for more than half a year. It would be great to add this to a release. Until then, we are stuck with silly fixes like:

from elasticsearch import AsyncElasticsearch
from elastic_transport import HttpxAsyncHttpNode, NodeConfig
class HttpxAsyncHttpNodeFixed(HttpxAsyncHttpNode):
    def __init__(self, config: NodeConfig):
        super().__init__(config)
        # This is just a fix to avoid omitting the path prefix in requests
        self.client.base_url = self.base_url

es = AsyncElasticsearch("http://example.com/elasticsearch", node_class=HttpxAsyncHttpNodeFixed)

@miguelgrinberg
Copy link
Contributor

I apologize for dropping the ball on this PR. I'll see that it gets merged and released over the next few days.

Copy link
Member

@pquentin pquentin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! LGTM. Note that the requests backend also lacks such a test.

@miguelgrinberg miguelgrinberg merged commit c8626a1 into elastic:main Dec 18, 2025
18 checks passed
github-actions bot pushed a commit that referenced this pull request Dec 23, 2025
* Use path_prefix to compute base_url in httpx

* unit test

* add similar unit test for requests nodes

---------

Co-authored-by: Miguel Grinberg <miguel.grinberg@gmail.com>
(cherry picked from commit c8626a1)
miguelgrinberg added a commit that referenced this pull request Dec 23, 2025
* Use path_prefix to compute base_url in httpx

* unit test

* add similar unit test for requests nodes

---------


(cherry picked from commit c8626a1)

Co-authored-by: Vincent Ruello <5345986+vruello@users.noreply.github.com>
Co-authored-by: Miguel Grinberg <miguel.grinberg@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants