# How to do custom score queries in elastic search 0.9 through java api?

**URL:** <https://discuss.elastic.co/t/how-to-do-custom-score-queries-in-elastic-search-0-9-through-java-api/3183>\
**Category:** Elasticsearch\
**Created:** [August 3, 2010, 12:01am UTC](https://discuss.elastic.co/t/how-to-do-custom-score-queries-in-elastic-search-0-9-through-java-api/3183 "2010-08-03T00:01:39Z")\
**Posts on this page:** 3\
**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 3, 2010, 12:01am UTC](https://discuss.elastic.co/t/how-to-do-custom-score-queries-in-elastic-search-0-9-through-java-api/3183/1 "2010-08-03T00:01:39Z")

</div>

How do I do a custom score query through the java client api?

I want to do what is described here, except do it through the java api:

> <https://github.com/elastic/elasticsearch/issues/220>

  
Is this possible, or do I have to use the REST api to get this functionality?

I assume it is not the method sort(java.lang.String s) on org.elasticsearch.search.builder.SearchSourceBuilder, as that method has been there at least since 0.8, and my understanding is that custom score queries are new in 0.9.

Thanks.

---

<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 3, 2010, 8:48am UTC](https://discuss.elastic.co/t/how-to-do-custom-score-queries-in-elastic-search-0-9-through-java-api/3183/2 "2010-08-03T08:48:24Z")

</div>

In your java code, you wrap the query that you execute with a  
customScoreQuery (from the static factory QueryBuilders). In general,  
everything that you have in the REST API is exposed in the Java API.

-shay.banon

On Tue, Aug 3, 2010 at 3:01 AM, John Chang [jchangkihtest2@gmail.com](mailto:jchangkihtest2@gmail.com) wrote:

> How do I do a custom score query through the java client api?
> 
> I want to do what is described here, except do it through the java api:  
> [Query DSL: custom score (scripted) query · Issue #220 · elastic/elasticsearch · GitHub](http://github.com/elasticsearch/elasticsearch/issues/220)  
> Is this possible, or do I have to use the REST api to get this  
> functionality?
> 
> I assume it is not the method sort(java.lang.String s) on  
> org.elasticsearch.search.builder.SearchSourceBuilder, as that method has  
> been there at least since 0.8, and my understanding is that custom score  
> queries are new in 0.9.
> 
> ## Thanks.
> 
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/How-to-do-custom-score-queries-in-elastic-search-0-9-through-java-api-tp1017635p1017635.html](http://elasticsearch-users.115913.n3.nabble.com/How-to-do-custom-score-queries-in-elastic-search-0-9-through-java-api-tp1017635p1017635.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:21am UTC](https://discuss.elastic.co/t/how-to-do-custom-score-queries-in-elastic-search-0-9-through-java-api/3183/3 "2017-07-06T04:21:12Z")

</div>


