Comments (1)
Hello! Per-request headers are supported with the .options()
API which creates a new Elasticsearch client and allows passing it various options, including headers. If you try the following example which enables debug logging:
from elasticsearch import Elasticsearch
import elastic_transport
elastic_transport.debug_logging()
es = Elasticsearch("http://localhost:9200")
es.index(index="test", document={"foo": "baz"})
es.options(headers={"custom": "header"}).index(index="test", document={"foo": "bar"})
You will see that the second request includes Custom: header
while the first does not:
[2024-03-29T11:17:57] > POST /test/_doc HTTP/1.1
> Accept: application/vnd.elasticsearch+json; compatible-with=8
> Connection: keep-alive
> Content-Type: application/vnd.elasticsearch+json; compatible-with=8
> User-Agent: elasticsearch-py/8.13.0 (Python/3.12.2; elastic-transport/8.13.0)
> X-Elastic-Client-Meta: es=8.13.0,py=3.12.2,t=8.13.0,ur=2.2.1
> {"foo":"baz"}
< HTTP/1.1 201 Created
< Location: /test/_doc/zR8SiY4BfFLxlYtpiETx
< X-Elastic-Product: Elasticsearch
< Content-Length: 156
< Content-Type: application/vnd.elasticsearch+json;compatible-with=8
< {"_index":"test","_id":"zR8SiY4BfFLxlYtpiETx","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":0,"_primary_term":1}
[2024-03-29T11:17:57] POST http://localhost:9200/test/_doc [status:201 duration:0.353s]
[2024-03-29T11:17:57] > POST /test/_doc HTTP/1.1
> Accept: application/vnd.elasticsearch+json; compatible-with=8
> Connection: keep-alive
> Content-Type: application/vnd.elasticsearch+json; compatible-with=8
> Custom: header
> User-Agent: elasticsearch-py/8.13.0 (Python/3.12.2; elastic-transport/8.13.0)
> X-Elastic-Client-Meta: es=8.13.0,py=3.12.2,t=8.13.0,ur=2.2.1
> {"foo":"bar"}
< HTTP/1.1 201 Created
< Location: /test/_doc/zh8SiY4BfFLxlYtpiURU
< X-Elastic-Product: Elasticsearch
< Content-Length: 156
< Content-Type: application/vnd.elasticsearch+json;compatible-with=8
< {"_index":"test","_id":"zh8SiY4BfFLxlYtpiURU","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":1,"_primary_term":1}
[2024-03-29T11:17:57] POST http://localhost:9200/test/_doc [status:201 duration:0.009s]
from elasticsearch-py.
Related Issues (20)
- Memory leak when using AsyncElasticsearch HOT 3
- search with nested sort results in 0 results HOT 8
- Helpers for `bulk` method such as `async_bulk` sleep in blocking manner, preventing graceful shutdown HOT 2
- `retry_on_status` setting does not work as expected with requests that should not be retried immediately
- es部署后索引无法创建 HOT 1
- [BUG] Missing type and settings parameters in _sync/snapshots & _async/snapshots create_respository methods HOT 3
- Incremented connection delay are not of the stated duration HOT 3
- client fails to connect to self-managed Elasticsearch instance at https://localhost:9200 using all methods described in documentation HOT 2
- Bulk action typing does not allow `TypedDict`
- Unexpected ilm.put_lifecycle behavior
- Unable to connect via AsyncElasticsearch using ssl fingerprint HOT 1
- [DOC] Add more Python Client code examples to main Elasticsearch Docs | Set up and Upgrade Elasticsearch HOT 2
- [Documentation] Access to specialized clients is not documented HOT 1
- Test failures against NumPy 2.0.0rc1
- 8.13.1: pytest fails with `ImportError: cannot import name 'OrjsonSerializer' from 'elasticsearch.serializer` in elasticsearch/serializer.py HOT 8
- Add update_trained_model_deployment to ML client HOT 1
- Improve typing of string enums
- Setting custom node_pool_class does not work and seems to be a typo HOT 2
- py>=3.10 client>7.10.0 can not run HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from elasticsearch-py.