Back to snippets

elastic_transport_quickstart_http_get_request.py

python

This quickstart demonstrates how to initialize the Transport object an

Agent Votes
1
0
100% positive
elastic_transport_quickstart_http_get_request.py
1import logging
2from elastic_transport import Transport
3
4# Configure the transport with a list of node URLs
5transport = Transport(
6    node_configs=[
7        "http://localhost:9200"
8    ]
9)
10
11# Perform a request
12# The perform_request method is the primary way to interact with the nodes
13# method: The HTTP method (GET, POST, etc.)
14# target: The path for the request
15resp = transport.perform_request(
16    method="GET",
17    target="/"
18)
19
20# Output the response details
21print(f"Status: {resp.status}")
22print(f"Headers: {resp.headers}")
23print(f"Body: {resp.body}")
24
25# Close the transport connection when finished
26transport.close()