# Specify search preference with Python API

**URL:** <https://discuss.elastic.co/t/specify-search-preference-with-python-api/70143>\
**Category:** Elasticsearch\
**Created:** [December 28, 2016, 1:55pm UTC](https://discuss.elastic.co/t/specify-search-preference-with-python-api/70143 "2016-12-28T13:55:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sam\_sak](https://avatars.discourse-cdn.com/v4/letter/s/839c29/32.png) [@sam\_sak](https://discuss.elastic.co/u/sam_sak)\
**Post date:** [December 28, 2016, 1:55pm UTC](https://discuss.elastic.co/t/specify-search-preference-with-python-api/70143/1 "2016-12-28T13:55:29Z")

</div>

Hi,

I am an ES novice and I would be thankful if anyone would help with my 'silly' question.  
How can I set my search preference using Python API ? Specifically, I need to specify the shard at each request. I can't find any example around..  
What I am looking exactly to do is what "slice" does, but since I 'am working on 1.7 it's not available.

Many thanks,  
S

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [December 29, 2016, 9:17am UTC](https://discuss.elastic.co/t/specify-search-preference-with-python-api/70143/2 "2016-12-29T09:17:15Z")

</div>

Hey,

search preference is not doing what the sliced scroll does. You still need to use a scroll request on 1.7 and live with less performance than a sliced scroll unless you upgrade (which you now have a great reason to! 🙂

--Alex

---

<div class="post-metadata">

**Author:** ![sam\_sak](https://avatars.discourse-cdn.com/v4/letter/s/839c29/32.png) [@sam\_sak](https://discuss.elastic.co/u/sam_sak)\
**Post date:** [January 2, 2017, 4:21pm UTC](https://discuss.elastic.co/t/specify-search-preference-with-python-api/70143/3 "2017-01-02T16:21:08Z")

</div>

Thanks for your reply Alex.

Actually this is exactly what I was doing, scrolling over each shard in order to simulate the sliced scroll though a slice == a shard is the finest (smallest) I can get.  
I have already found the syntax for the python API and here's and example for doing a scroll over shard number **2** :

`esObj.search(index=esIndex, doc_type= esTypeName, scroll = scrollTimeout, search_type = 'scan', size = scNum, preference = "_shards:2", body = queryJson)`

---

<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:** [January 30, 2017, 4:21pm UTC](https://discuss.elastic.co/t/specify-search-preference-with-python-api/70143/4 "2017-01-30T16:21:12Z")

</div>

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