# Search type in custom score queries

**URL:** <https://discuss.elastic.co/t/search-type-in-custom-score-queries/3240>\
**Category:** Elasticsearch\
**Created:** [August 19, 2010, 7:09pm UTC](https://discuss.elastic.co/t/search-type-in-custom-score-queries/3240 "2010-08-19T19:09:09Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Chang](https://avatars.discourse-cdn.com/v4/letter/j/ecc23a/32.png) [@John\_Chang](https://discuss.elastic.co/u/John_Chang)\
**Post date:** [August 19, 2010, 7:09pm UTC](https://discuss.elastic.co/t/search-type-in-custom-score-queries/3240/1 "2010-08-19T19:09:09Z")

</div>

I am doing some normal custom queries through the java api, and some custom score queries through the java api.

My non scored queries used SearchType DFS\_QUERY\_THEN\_FETCH. However, I see in the unit test org.elasticsearch.test.integration.search.customscore.CustomScoreSearchTests that the SearchType is QUERY\_THEN\_FETCH.

A few questions:

1. Is QUERY\_THEN\_FETCH the preferred (or mandatory) search type for custom score queries?
2. Either way, I'm getting failures if I do custom score queries (although they worked before, not sure why I have the problems now). If I do a custom score query with DFS\_QUERY\_THEN\_FETCH, I get no results back. If I do QUERY\_THEN\_FETCH, the the client gets this CLIENT EXCEPTION below, and the server prints the SERVER ERROR below. When I do the exact same query but without custom scoring (using DFS\_QUERY\_THEN\_FETCH) I get the correct results back.

CLIENT EXCEPTION: (when doing custom score with QUERY\_THEN\_FETCH)  
org.elasticsearch.action.search.SearchPhaseExecutionException: Failed to execute phase [query], total failure; shardFailures {[3ccbea0e-b8d6-4440-af3a-71761b3eabfa][index0][1]: RemoteTransportException[[Thena][inet[/10.3.3.156:9300]][search/phase/query]]; nested: QueryPhaseExecutionException[[index0][1]: query[custom score .(+userId:34c40bec15234b4abb900413d464c68b +(body:subject\* subject:subject\* to:subject\* from:subject\* cc:subject\*),function=org.elasticsearch.index.query.xcontent.CustomScoreQueryParser$ScriptScoreFunction@113ee167)],from[0],size[1000]: Query Failed [Failed to execute main query]];....

SERVER ERROR: (when doing custom score with QUERY\_THEN\_FETCH)  
[12:03:31,942][INFO][cluster.service] [Thena] removed {[Balder][292c279e-cae2-435a-a94e-85f9fd6dadf0][inet[/10.3.3.156:9302]]{client=true, data=false, zen.master=false},}, reason: zen-disco-node\_failed([Balder][292c279e-cae2-435a-a94e-85f9fd6dadf0][inet[/10.3.3.156:9302]]{client=true, data=false, zen.master=false}), reason transport disconnected

---

<div class="post-metadata">

**Author:** ![John\_Chang](https://avatars.discourse-cdn.com/v4/letter/j/ecc23a/32.png) [@John\_Chang](https://discuss.elastic.co/u/John_Chang)\
**Post date:** [August 19, 2010, 7:45pm UTC](https://discuss.elastic.co/t/search-type-in-custom-score-queries/3240/2 "2010-08-19T19:45:51Z")

</div>

I should add that when I do the QUERY\_THEN\_FETCH and get the error server-side reading 'transport disconnected', I can still go back with the same client instance and index more documents without any reconnect steps.

---

<div class="post-metadata">

**Author:** ![John\_Chang](https://avatars.discourse-cdn.com/v4/letter/j/ecc23a/32.png) [@John\_Chang](https://discuss.elastic.co/u/John_Chang)\
**Post date:** [August 19, 2010, 8:05pm UTC](https://discuss.elastic.co/t/search-type-in-custom-score-queries/3240/3 "2010-08-19T20:05:03Z")

</div>

Please ignore the stuff about the "SERVER ERROR" above. That has nothing to do with it; it was just the normal message logged on the server when my test is done and goes out of scope. It happens even on the successful non-sorted queries when the test client vm goes away. Sorry. However, I still do believe the client-side exception is a problem.

---

<div class="post-metadata">

**Author:** ![John\_Chang](https://avatars.discourse-cdn.com/v4/letter/j/ecc23a/32.png) [@John\_Chang](https://discuss.elastic.co/u/John_Chang)\
**Post date:** [August 19, 2010, 8:42pm UTC](https://discuss.elastic.co/t/search-type-in-custom-score-queries/3240/4 "2010-08-19T20:42:48Z")

</div>

I fixed the exception - I had mapped the field I wanted to sort on as a string and not a float. Sorry. But still, if you could comment on the preferred QueryType for sorted searches, I'd appreciate it.

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [August 19, 2010, 9:53pm UTC](https://discuss.elastic.co/t/search-type-in-custom-score-queries/3240/5 "2010-08-19T21:53:40Z")

</div>

The preferred type is QUERY\_THEN\_FETCH, thats why its the default ;). if you  
want exact scoring, then you can use DFS one (assuming the distribution of  
terms is really different between shards).

-shay.banon

On Thu, Aug 19, 2010 at 11:42 PM, John Chang [jchangkihtest2@gmail.com](mailto:jchangkihtest2@gmail.com)wrote:

> ## I fixed the exception - I had mapped the field I wanted to sort on as a string and not a float. Sorry. But still, if you could comment on the preferred QueryType for sorted searches, I'd appreciate it.
> 
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/Search-type-in-custom-score-queries-tp1230940p1232662.html](http://elasticsearch-users.115913.n3.nabble.com/Search-type-in-custom-score-queries-tp1230940p1232662.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<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:** [July 6, 2017, 4:20am UTC](https://discuss.elastic.co/t/search-type-in-custom-score-queries/3240/6 "2017-07-06T04:20:31Z")

</div>


