# Bulk via Python to Kubernetes cluster

**URL:** https://discuss.elastic.co/t/bulk-via-python-to-kubernetes-cluster/329065
**Category:** Elasticsearch
**Created:** [March 31, 2023, 3:18pm UTC](https://discuss.elastic.co/t/bulk-via-python-to-kubernetes-cluster/329065 "2023-03-31T15:18:51Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Itay\_Bittan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/itay_bittan/32/23527_2.png) [@Itay\_Bittan](https://discuss.elastic.co/u/Itay_Bittan)
#### Post date: [March 31, 2023, 3:18pm UTC](https://discuss.elastic.co/t/bulk-via-python-to-kubernetes-cluster/329065/1 "2023-03-31T15:18:51Z")

</div>

Hi!

We are heavily indexing to Elasticsearch 8.6.1 via Python code using bulk API.  
Our cluster runs on Kubernetes with the elastic operator which creates the following services:

```auto
my-cluster-es-data
my-cluster-es-http
my-cluster-es-internal-http
my-cluster-es-master
my-cluster-es-transport

```

In Python I'm creating es client like that:

```auto
es_conn = AsyncElasticsearch(hosts="http://my-cluster-es-http.my-ns.svc.cluster.local:9200")

```

On one hand, I think that it's good because the service wraps all nodes and will always route to an **available** node. On the other hand, it feels like it is better to provide the client with all the nodes, and maybe it will do something better for a faster interaction (round robin?) and finally a faster indexing.

What's it correct? am I doing it right?  
Thanks

---

<div class="post-metadata">

### Author: ![Wave](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wave/32/117242_2.png) [@Wave](https://discuss.elastic.co/u/Wave)
#### Post date: [April 4, 2023, 10:14pm UTC](https://discuss.elastic.co/t/bulk-via-python-to-kubernetes-cluster/329065/2 "2023-04-04T22:14:46Z")

</div>

Hi @Itay_Bittan,  
I haven't used the bulk api via python, but according to the [documentation](https://elasticsearch-py.readthedocs.io/en/master/async.html#asyncelasticsearch) it looks like you should be able to define multiple hosts if you want. Hopefully trying out hosts will let you know if it gives you better performance.

---

<div class="post-metadata">

### Author: ![Itay\_Bittan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/itay_bittan/32/23527_2.png) [@Itay\_Bittan](https://discuss.elastic.co/u/Itay_Bittan)
#### Post date: [April 5, 2023, 5:59am UTC](https://discuss.elastic.co/t/bulk-via-python-to-kubernetes-cluster/329065/3 "2023-04-05T05:59:02Z")

</div>

thanks @Wave!  
I saw it and that's why I asked.  
On the other hand, Kubernetes service resource should give you a kind of abstraction - so you won't have to update your application whenever a node joins/left the cluster (the `hosts` list).  
I wonder if any of the approaches promise a kind of load balancing across all nodes.

---

<div class="post-metadata">

### Author: ![Wave](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wave/32/117242_2.png) [@Wave](https://discuss.elastic.co/u/Wave)
#### Post date: [April 5, 2023, 1:46pm UTC](https://discuss.elastic.co/t/bulk-via-python-to-kubernetes-cluster/329065/4 "2023-04-05T13:46:38Z")

</div>

That makes sense. My hunch is using a host list will load balance. That's how it works everywhere else in the elastic stack when multiple hosts are provided. Might be a good experiment to find out for sure.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [May 3, 2023, 1:47pm UTC](https://discuss.elastic.co/t/bulk-via-python-to-kubernetes-cluster/329065/5 "2023-05-03T13:47:00Z")

</div>

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