# Dfs\_query\_then\_fetch value not working with SearchRequestBuilder.setSearchType

**URL:** <https://discuss.elastic.co/t/dfs-query-then-fetch-value-not-working-with-searchrequestbuilder-setsearchtype/150603>\
**Category:** Elasticsearch\
**Created:** [October 1, 2018, 7:30pm UTC](https://discuss.elastic.co/t/dfs-query-then-fetch-value-not-working-with-searchrequestbuilder-setsearchtype/150603 "2018-10-01T19:30:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![wmebed](https://avatars.discourse-cdn.com/v4/letter/w/258eb7/32.png) [@wmebed](https://discuss.elastic.co/u/wmebed)\
**Post date:** [October 1, 2018, 7:30pm UTC](https://discuss.elastic.co/t/dfs-query-then-fetch-value-not-working-with-searchrequestbuilder-setsearchtype/150603/1 "2018-10-01T19:30:08Z")

</div>

I implemented an ActionPlugin by extending BaseRestHandler. But when I set the searchType (searchRequestBuilder.setSearchType(SearchType.DFS\_QUERY\_THEN\_FETCH).execute().get()....) it isn't being honored. I can tell the DFS\_QUERY\_THEN\_FETCH isn't working because the scoring is different with the same query executed twice.

Using the REST api externally (via curl) works:  
GET /product/\_search?search\_type=dfs\_query\_then\_fetch ...

Using ElasticSearch 6.1.0.  
The index has two replicas.  
{  
"cluster\_name": "stage-1",  
"status": "green",  
"timed\_out": false,  
"number\_of\_nodes": 2,  
"number\_of\_data\_nodes": 2,  
"active\_primary\_shards": 10,  
"active\_shards": 20,  
"relocating\_shards": 0,  
"initializing\_shards": 0,  
"unassigned\_shards": 0,  
"delayed\_unassigned\_shards": 0,  
"number\_of\_pending\_tasks": 0,  
"number\_of\_in\_flight\_fetch": 0,  
"task\_max\_waiting\_in\_queue\_millis": 0,  
"active\_shards\_percent\_as\_number": 100,  
"indices": {  
"product\_index.json": {  
"status": "green",  
"number\_of\_shards": 5,  
"number\_of\_replicas": 1,  
"active\_primary\_shards": 5,  
"active\_shards": 10,  
"relocating\_shards": 0,  
"initializing\_shards": 0,  
"unassigned\_shards": 0  
},  
"product": {  
"status": "green",  
"number\_of\_shards": 5,  
"number\_of\_replicas": 1,  
"active\_primary\_shards": 5,  
"active\_shards": 10,  
"relocating\_shards": 0,  
"initializing\_shards": 0,  
"unassigned\_shards": 0  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![wmebed](https://avatars.discourse-cdn.com/v4/letter/w/258eb7/32.png) [@wmebed](https://discuss.elastic.co/u/wmebed)\
**Post date:** [October 2, 2018, 9:32pm UTC](https://discuss.elastic.co/t/dfs-query-then-fetch-value-not-working-with-searchrequestbuilder-setsearchtype/150603/2 "2018-10-02T21:32:47Z")

</div>

Maybe DFS\_QUERY\_THEN\_FETCH option on searchRequestBuilder is being honored. It's just not working the way I initially understood.

I ended up using preference parameter, and that seems to make queries repeatable in terms of scoring and result order.

---

<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 30, 2018, 9:32pm UTC](https://discuss.elastic.co/t/dfs-query-then-fetch-value-not-working-with-searchrequestbuilder-setsearchtype/150603/3 "2018-10-30T21:32:57Z")

</div>

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