# How to only query on data nodes by elasticsearch-py?

**URL:** <https://discuss.elastic.co/t/how-to-only-query-on-data-nodes-by-elasticsearch-py/249293>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [September 21, 2020, 3:32am UTC](https://discuss.elastic.co/t/how-to-only-query-on-data-nodes-by-elasticsearch-py/249293 "2020-09-21T03:32:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![derobukal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/derobukal/32/66248_2.png) [@derobukal](https://discuss.elastic.co/u/derobukal)\
**Post date:** [September 21, 2020, 3:32am UTC](https://discuss.elastic.co/t/how-to-only-query-on-data-nodes-by-elasticsearch-py/249293/1 "2020-09-21T03:32:25Z")

</div>

I am using elasticsearch-py, which version is 7.5.1.

I have 3 master nodes and 6 data nodes, master nodes have 2gb heap and data nodes have 30 gb heap.

How can I only query data on my data nodes? I read the source code `transport.py` in elasticsearch-py, and it will get all nodes by using `"/_nodes/_all/http"` API.

When query from master nodes, the memory of master nodes will have pressure and i will get circuit\_breaking\_exception.

How can I query without master nodes? thanks.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [September 21, 2020, 5:37am UTC](https://discuss.elastic.co/t/how-to-only-query-on-data-nodes-by-elasticsearch-py/249293/2 "2020-09-21T05:37:25Z")

</div>

Welcome to our community! 😃

I don't think the client has the ability to differentiate, it's not explicitly called out in the docs that I could see. Hopefully one of the client team engineers can confirm either way.

---

<div class="post-metadata">

**Author:** ![derobukal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/derobukal/32/66248_2.png) [@derobukal](https://discuss.elastic.co/u/derobukal)\
**Post date:** [September 22, 2020, 3:06am UTC](https://discuss.elastic.co/t/how-to-only-query-on-data-nodes-by-elasticsearch-py/249293/3 "2020-09-22T03:06:07Z")

</div>

I have got the answer on GitHub, for people who has the same question, you can view [this link](https://github.com/elastic/elasticsearch-py/issues/1378#issuecomment-696197432) for more information.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [September 22, 2020, 4:00am UTC](https://discuss.elastic.co/t/how-to-only-query-on-data-nodes-by-elasticsearch-py/249293/4 "2020-09-22T04:00:39Z")

</div>

Copying the response here as well;

> You can modify how the `Transport` chooses which nodes to use after a sniff by setting `host_info_callback` :
> 
> ```auto
> def only_data_nodes(node_info, host):
> roles = node_info.get("roles", [])
> return host if ("data" in roles and "master" not in roles) else None
> 
> es = Elasticsearch(host_info_callback=only_data_nodes, sniff_on_start=True)
> 
> ```
> 
> The above will only make requests to nodes which don't have the `master` role but do have the `data` role. You can modify it how you see fit. Does that answer you question?

---

<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:** [October 20, 2020, 4:00am UTC](https://discuss.elastic.co/t/how-to-only-query-on-data-nodes-by-elasticsearch-py/249293/5 "2020-10-20T04:00:45Z")

</div>

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