# Elasticsearch Java API for function\_score query

**URL:** <https://discuss.elastic.co/t/elasticsearch-java-api-for-function-score-query/18011>\
**Category:** Elasticsearch\
**Created:** [June 10, 2014, 9:16am UTC](https://discuss.elastic.co/t/elasticsearch-java-api-for-function-score-query/18011 "2014-06-10T09:16:54Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jayanth\_Inakollu](https://avatars.discourse-cdn.com/v4/letter/j/8edcca/32.png) [@Jayanth\_Inakollu](https://discuss.elastic.co/u/Jayanth_Inakollu)\
**Post date:** [June 10, 2014, 9:16am UTC](https://discuss.elastic.co/t/elasticsearch-java-api-for-function-score-query/18011/1 "2014-06-10T09:16:54Z")

</div>

I need to implement the below function\_score query using Java APIs. I  
couldn't find any official documentation for function\_score query in the  
Java API section of elasticsearch

"function\_score": {  
"functions": [  
{  
"boost\_factor": "3",  
"filter": {  
"terms" : {"course\_cd" : ["writ100", "writ112", "writ113"]  
}  
}  
}  
],  
"query": {  
"match" : {  
"party\_id" : "12"  
}  
}  
}

Please help!

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/56d92aab-a4d7-4757-9441-f248c5296b3c%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/56d92aab-a4d7-4757-9441-f248c5296b3c%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [June 10, 2014, 8:39pm UTC](https://discuss.elastic.co/t/elasticsearch-java-api-for-function-score-query/18011/2 "2014-06-10T20:39:45Z")

</div>

Try this

import org.elasticsearch.action.search.SearchRequest;  
import  
org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder;

import java.util.Arrays;

import static org.elasticsearch.client.Requests.searchRequest;  
import static org.elasticsearch.index.query.FilterBuilders.termsFilter;  
import static org.elasticsearch.index.query.QueryBuilders.matchQuery;  
import static  
org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders.factorFunction;  
import static  
org.elasticsearch.search.builder.SearchSourceBuilder.searchSource;

public class FunctionScoreTest {

```
public void testFunctionScore() {
    SearchRequest searchRequest = searchRequest()
            .source(searchSource().query(new

```

FunctionScoreQueryBuilder(matchQuery("party\_id", "12"))  
.add(termsFilter("course\_cd",  
Arrays.asList("writ100", "writ112", "writ113")), factorFunction(3.0f))));  
}  
}

Jörg

On Tue, Jun 10, 2014 at 11:16 AM, Jayanth Inakollu \<[ibsjayanth2309@gmail.com](mailto:ibsjayanth2309@gmail.com)

> wrote:

> I need to implement the below function\_score query using Java APIs. I  
> couldn't find any official documentation for function\_score query in the  
> Java API section of elasticsearch
> 
> "function\_score": {  
> "functions": [  
> {  
> "boost\_factor": "3",  
> "filter": {  
> "terms" : {"course\_cd" : ["writ100", "writ112", "writ113"  
> ] }  
> }  
> }  
> ],  
> "query": {  
> "match" : {  
> "party\_id" : "12"  
> }  
> }  
> }
> 
> Please help!
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/56d92aab-a4d7-4757-9441-f248c5296b3c%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/56d92aab-a4d7-4757-9441-f248c5296b3c%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/56d92aab-a4d7-4757-9441-f248c5296b3c%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/56d92aab-a4d7-4757-9441-f248c5296b3c%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAKdsXoHBk2\_PtoJkriZrvA-1B7vqB%3DhSLnaXOwFEkgeugsOZsQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAKdsXoHBk2_PtoJkriZrvA-1B7vqB%3DhSLnaXOwFEkgeugsOZsQ%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Jayanth\_Inakollu](https://avatars.discourse-cdn.com/v4/letter/j/8edcca/32.png) [@Jayanth\_Inakollu](https://discuss.elastic.co/u/Jayanth_Inakollu)\
**Post date:** [June 12, 2014, 10:52am UTC](https://discuss.elastic.co/t/elasticsearch-java-api-for-function-score-query/18011/3 "2014-06-12T10:52:48Z")

</div>

Thanks a lot!! It works!!

On Wednesday, June 11, 2014 2:09:57 AM UTC+5:30, Jörg Prante wrote:

> Try this
> 
> import org.elasticsearch.action.search.SearchRequest;  
> import  
> org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder;
> 
> import java.util.Arrays;
> 
> import static org.elasticsearch.client.Requests.searchRequest;  
> import static org.elasticsearch.index.query.FilterBuilders.termsFilter;  
> import static org.elasticsearch.index.query.QueryBuilders.matchQuery;  
> import static  
> org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders.factorFunction;  
> import static  
> org.elasticsearch.search.builder.SearchSourceBuilder.searchSource;
> 
> public class FunctionScoreTest {
> 
> ```
> public void testFunctionScore() {
> SearchRequest searchRequest = searchRequest()
> .source(searchSource().query(new 
> 
> ```
> 
> FunctionScoreQueryBuilder(matchQuery("party\_id", "12"))  
> .add(termsFilter("course\_cd",  
> Arrays.asList("writ100", "writ112", "writ113")), factorFunction(3.0f))));  
> }  
> }
> 
> Jörg
> 
> On Tue, Jun 10, 2014 at 11:16 AM, Jayanth Inakollu \<[ibsjaya...@gmail.com](mailto:ibsjaya...@gmail.com)  
> \<javascript:\>\> wrote:
> 
> > I need to implement the below function\_score query using Java APIs. I  
> > couldn't find any official documentation for function\_score query in the  
> > Java API section of elasticsearch
> > 
> > "function\_score": {  
> > "functions": [  
> > {  
> > "boost\_factor": "3",  
> > "filter": {  
> > "terms" : {"course\_cd" : ["writ100", "writ112",  
> > "writ113"] }  
> > }  
> > }  
> > ],  
> > "query": {  
> > "match" : {  
> > "party\_id" : "12"  
> > }  
> > }  
> > }
> > 
> > Please help!
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/56d92aab-a4d7-4757-9441-f248c5296b3c%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/56d92aab-a4d7-4757-9441-f248c5296b3c%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/56d92aab-a4d7-4757-9441-f248c5296b3c%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/56d92aab-a4d7-4757-9441-f248c5296b3c%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/a03661cb-5310-42ca-996d-e2e137376bb1%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/a03661cb-5310-42ca-996d-e2e137376bb1%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Malini](https://avatars.discourse-cdn.com/v4/letter/m/f05b48/32.png) [@Malini](https://discuss.elastic.co/u/Malini)\
**Post date:** [September 9, 2014, 11:28pm UTC](https://discuss.elastic.co/t/elasticsearch-java-api-for-function-score-query/18011/4 "2014-09-09T23:28:03Z")

</div>

How do I implement the following query using Java ApI? Thanks!

curl -XGET [http://localhost:9200/cs/csdl/\_search?pretty=true](http://localhost:9200/cs/csdl/_search?pretty=true) -d '  
{  
"query":{  
"function\_score": {  
"functions": [  
{  
"boost\_factor": "-10",  
"filter": {  
"terms" : {"abbrev" : ["computer"] }  
}  
}  
],  
"query": {  
"filtered": {  
"query" : {  
"multi\_match" : {  
"fields" : ["title"],  
"query" : ["computer"]

```
        }
        },
        "filter": {
          "bool": {
        "must": { "range": { 
                         "pubdate": { 
                    "gte": "1890-09" ,
                            "lte":"2014-08"
                      }
                       }
             },

         "must" : {
            "terms" : { 
               "abbrev" : ["computer","annals","software"]
             }
        }
          }
        }
  }
 }
}

```

}  
}'

On Tuesday, June 10, 2014 1:39:57 PM UTC-7, Jörg Prante wrote:

> Try this
> 
> import org.elasticsearch.action.search.SearchRequest;  
> import  
> org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder;
> 
> import java.util.Arrays;
> 
> import static org.elasticsearch.client.Requests.searchRequest;  
> import static org.elasticsearch.index.query.FilterBuilders.termsFilter;  
> import static org.elasticsearch.index.query.QueryBuilders.matchQuery;  
> import static  
> org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders.factorFunction;  
> import static  
> org.elasticsearch.search.builder.SearchSourceBuilder.searchSource;
> 
> public class FunctionScoreTest {
> 
> ```
> public void testFunctionScore() {
> SearchRequest searchRequest = searchRequest()
> .source(searchSource().query(new 
> 
> ```
> 
> FunctionScoreQueryBuilder(matchQuery("party\_id", "12"))  
> .add(termsFilter("course\_cd",  
> Arrays.asList("writ100", "writ112", "writ113")), factorFunction(3.0f))));  
> }  
> }
> 
> Jörg
> 
> On Tue, Jun 10, 2014 at 11:16 AM, Jayanth Inakollu \<[ibsjaya...@gmail.com](mailto:ibsjaya...@gmail.com)  
> \<javascript:\>\> wrote:
> 
> > I need to implement the below function\_score query using Java APIs. I  
> > couldn't find any official documentation for function\_score query in the  
> > Java API section of elasticsearch
> > 
> > "function\_score": {  
> > "functions": [  
> > {  
> > "boost\_factor": "3",  
> > "filter": {  
> > "terms" : {"course\_cd" : ["writ100", "writ112",  
> > "writ113"] }  
> > }  
> > }  
> > ],  
> > "query": {  
> > "match" : {  
> > "party\_id" : "12"  
> > }  
> > }  
> > }
> > 
> > Please help!
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/56d92aab-a4d7-4757-9441-f248c5296b3c%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/56d92aab-a4d7-4757-9441-f248c5296b3c%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/56d92aab-a4d7-4757-9441-f248c5296b3c%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/56d92aab-a4d7-4757-9441-f248c5296b3c%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/311c8492-8e78-4188-847c-44d7d115b464%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/311c8492-8e78-4188-847c-44d7d115b464%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [September 10, 2014, 2:33am UTC](https://discuss.elastic.co/t/elasticsearch-java-api-for-function-score-query/18011/5 "2014-09-10T02:33:44Z")

</div>

Malini, I would suggest starting a new thread instead of adding to an old  
one.

I find the Java API for the boost functions to be confusing, or at least,  
not as clean as the rest of the Java API. I wonder if the Elasticsearch  
team would accept a PR. Jörg's example above could be used as a skeleton  
for your code. Something like

new FunctionScoreQueryBuilder(existingFilteredQuery)  
.add(termsFilter("abbrev", "computer"), factorFunction(-10f))

--  
Ivan

On Tue, Sep 9, 2014 at 4:28 PM, Malini [malini.ramaprasad@gmail.com](mailto:malini.ramaprasad@gmail.com) wrote:

> How do I implement the following query using Java ApI? Thanks!
> 
> curl -XGET [http://localhost:9200/cs/csdl/\_search?pretty=true](http://localhost:9200/cs/csdl/_search?pretty=true) -d '  
> {  
> "query":{  
> "function\_score": {  
> "functions": [  
> {  
> "boost\_factor": "-10",  
> "filter": {  
> "terms" : {"abbrev" : ["computer"] }  
> }  
> }  
> ],  
> "query": {  
> "filtered": {  
> "query" : {  
> "multi\_match" : {  
> "fields" : ["title"],  
> "query" : ["computer"]
> 
> ```
> }
> },
> "filter": {
> "bool": {
> "must": { "range": {
> "pubdate": {
> "gte": "1890-09" ,
> "lte":"2014-08"
> }
> }
> },
> 
> "must" : {
> "terms" : {
> "abbrev" : ["computer","annals","software"]
> }
> }
> }
> }
> }
> }
> }
> 
> ```
> 
> }  
> }'
> 
> On Tuesday, June 10, 2014 1:39:57 PM UTC-7, Jörg Prante wrote:
> 
> > Try this
> > 
> > import org.elasticsearch.action.search.SearchRequest;  
> > import org.elasticsearch.index.query.functionscore.  
> > FunctionScoreQueryBuilder;
> > 
> > import java.util.Arrays;
> > 
> > import static org.elasticsearch.client.Requests.searchRequest;  
> > import static org.elasticsearch.index.query.FilterBuilders.termsFilter;  
> > import static org.elasticsearch.index.query.QueryBuilders.matchQuery;  
> > import static org.elasticsearch.index.query.functionscore.  
> > ScoreFunctionBuilders.factorFunction;  
> > import static org.elasticsearch.search.builder.SearchSourceBuilder.  
> > searchSource;
> > 
> > public class FunctionScoreTest {
> > 
> > ```
> > public void testFunctionScore() {
> > SearchRequest searchRequest = searchRequest()
> > .source(searchSource().query(new
> > 
> > ```
> > 
> > FunctionScoreQueryBuilder(matchQuery("party\_id", "12"))  
> > .add(termsFilter("course\_cd",  
> > Arrays.asList("writ100", "writ112", "writ113")), factorFunction(3.0f))));  
> > }  
> > }
> > 
> > Jörg
> > 
> > On Tue, Jun 10, 2014 at 11:16 AM, Jayanth Inakollu [ibsjaya...@gmail.com](mailto:ibsjaya...@gmail.com)  
> > wrote:
> > 
> > > I need to implement the below function\_score query using Java APIs. I  
> > > couldn't find any official documentation for function\_score query in the  
> > > Java API section of elasticsearch
> > > 
> > > "function\_score": {  
> > > "functions": [  
> > > {  
> > > "boost\_factor": "3",  
> > > "filter": {  
> > > "terms" : {"course\_cd" : ["writ100", "writ112",  
> > > "writ113"] }  
> > > }  
> > > }  
> > > ],  
> > > "query": {  
> > > "match" : {  
> > > "party\_id" : "12"  
> > > }  
> > > }  
> > > }
> > > 
> > > Please help!
> > > 
> > > --  
> > > You received this message because you are subscribed to the Google  
> > > Groups "elasticsearch" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send  
> > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > To view this discussion on the web visit [https://groups.google.com/d/](https://groups.google.com/d/)  
> > > msgid/elasticsearch/56d92aab-a4d7-4757-9441-f248c5296b3c%  
> > > [40googlegroups.com](http://40googlegroups.com)  
> > > [https://groups.google.com/d/msgid/elasticsearch/56d92aab-a4d7-4757-9441-f248c5296b3c%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/56d92aab-a4d7-4757-9441-f248c5296b3c%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > .  
> > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/311c8492-8e78-4188-847c-44d7d115b464%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/311c8492-8e78-4188-847c-44d7d115b464%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/311c8492-8e78-4188-847c-44d7d115b464%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/311c8492-8e78-4188-847c-44d7d115b464%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .
> 
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQCzs6fjav3SMMaf8vT79kMEccyC3-HWwK\_wCjC8mYXQBw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQCzs6fjav3SMMaf8vT79kMEccyC3-HWwK_wCjC8mYXQBw%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![mramaprasad](https://avatars.discourse-cdn.com/v4/letter/m/ad7895/32.png) [@mramaprasad](https://discuss.elastic.co/u/mramaprasad)\
**Post date:** [September 10, 2014, 5:17pm UTC](https://discuss.elastic.co/t/elasticsearch-java-api-for-function-score-query/18011/6 "2014-09-10T17:17:47Z")

</div>

It worked. Thank you Ivan.

On Tuesday, September 9, 2014 7:33:58 PM UTC-7, Ivan Brusic wrote:

> Malini, I would suggest starting a new thread instead of adding to an old  
> one.
> 
> I find the Java API for the boost functions to be confusing, or at least,  
> not as clean as the rest of the Java API. I wonder if the Elasticsearch  
> team would accept a PR. Jörg's example above could be used as a skeleton  
> for your code. Something like
> 
> new FunctionScoreQueryBuilder(existingFilteredQuery)  
> .add(termsFilter("abbrev", "computer"), factorFunction(-10f))
> 
> --  
> Ivan
> 
> On Tue, Sep 9, 2014 at 4:28 PM, Malini \<[malini.r...@gmail.com](mailto:malini.r...@gmail.com)  
> \<javascript:\>\> wrote:
> 
> > How do I implement the following query using Java ApI? Thanks!
> > 
> > curl -XGET [http://localhost:9200/cs/csdl/\_search?pretty=true](http://localhost:9200/cs/csdl/_search?pretty=true) -d '  
> > {  
> > "query":{  
> > "function\_score": {  
> > "functions": [  
> > {  
> > "boost\_factor": "-10",  
> > "filter": {  
> > "terms" : {"abbrev" : ["computer"] }  
> > }  
> > }  
> > ],  
> > "query": {  
> > "filtered": {  
> > "query" : {  
> > "multi\_match" : {  
> > "fields" : ["title"],  
> > "query" : ["computer"]
> > 
> > ```
> > }
> > },
> > "filter": {
> > "bool": {
> > "must": { "range": { 
> > "pubdate": { 
> > "gte": "1890-09" ,
> > "lte":"2014-08"
> > }
> > }
> > },
> > 
> > "must" : {
> > "terms" : { 
> > "abbrev" : ["computer","annals","software"]
> > }
> > }
> > }
> > }
> > }
> > }
> > }
> > 
> > ```
> > 
> > }  
> > }'
> > 
> > On Tuesday, June 10, 2014 1:39:57 PM UTC-7, Jörg Prante wrote:
> > 
> > > Try this
> > > 
> > > import org.elasticsearch.action.search.SearchRequest;  
> > > import org.elasticsearch.index.query.functionscore.  
> > > FunctionScoreQueryBuilder;
> > > 
> > > import java.util.Arrays;
> > > 
> > > import static org.elasticsearch.client.Requests.searchRequest;  
> > > import static org.elasticsearch.index.query.FilterBuilders.termsFilter;  
> > > import static org.elasticsearch.index.query.QueryBuilders.matchQuery;  
> > > import static org.elasticsearch.index.query.functionscore.  
> > > ScoreFunctionBuilders.factorFunction;  
> > > import static org.elasticsearch.search.builder.SearchSourceBuilder.  
> > > searchSource;
> > > 
> > > public class FunctionScoreTest {
> > > 
> > > ```
> > > public void testFunctionScore() {
> > > SearchRequest searchRequest = searchRequest()
> > > .source(searchSource().query(new 
> > > 
> > > ```
> > > 
> > > FunctionScoreQueryBuilder(matchQuery("party\_id", "12"))  
> > > .add(termsFilter("course\_cd",  
> > > Arrays.asList("writ100", "writ112", "writ113")), factorFunction(3.0f))));  
> > > }  
> > > }
> > > 
> > > Jörg
> > > 
> > > On Tue, Jun 10, 2014 at 11:16 AM, Jayanth Inakollu \<[ibsjaya...@gmail.com](mailto:ibsjaya...@gmail.com)
> > > 
> > > > wrote:
> > > 
> > > > I need to implement the below function\_score query using Java APIs. I  
> > > > couldn't find any official documentation for function\_score query in the  
> > > > Java API section of elasticsearch
> > > > 
> > > > "function\_score": {  
> > > > "functions": [  
> > > > {  
> > > > "boost\_factor": "3",  
> > > > "filter": {  
> > > > "terms" : {"course\_cd" : ["writ100", "writ112",  
> > > > "writ113"] }  
> > > > }  
> > > > }  
> > > > ],  
> > > > "query": {  
> > > > "match" : {  
> > > > "party\_id" : "12"  
> > > > }  
> > > > }  
> > > > }
> > > > 
> > > > Please help!
> > > > 
> > > > --  
> > > > You received this message because you are subscribed to the Google  
> > > > Groups "elasticsearch" group.  
> > > > To unsubscribe from this group and stop receiving emails from it, send  
> > > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > To view this discussion on the web visit [https://groups.google.com/d/](https://groups.google.com/d/)  
> > > > msgid/elasticsearch/56d92aab-a4d7-4757-9441-f248c5296b3c%  
> > > > [40googlegroups.com](http://40googlegroups.com)  
> > > > [https://groups.google.com/d/msgid/elasticsearch/56d92aab-a4d7-4757-9441-f248c5296b3c%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/56d92aab-a4d7-4757-9441-f248c5296b3c%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > > .  
> > > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > > 
> > > --  
> > > You received this message because you are subscribed to the Google Groups  
> > > "elasticsearch" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send an  
> > > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > > To view this discussion on the web visit  
> > > [https://groups.google.com/d/msgid/elasticsearch/311c8492-8e78-4188-847c-44d7d115b464%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/311c8492-8e78-4188-847c-44d7d115b464%40googlegroups.com)  
> > > [https://groups.google.com/d/msgid/elasticsearch/311c8492-8e78-4188-847c-44d7d115b464%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/311c8492-8e78-4188-847c-44d7d115b464%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > .
> > 
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/fb8ed6a8-541e-4a55-8a59-f100b48a2938%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/fb8ed6a8-541e-4a55-8a59-f100b48a2938%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 1:03am UTC](https://discuss.elastic.co/t/elasticsearch-java-api-for-function-score-query/18011/7 "2017-07-06T01:03:15Z")

</div>


