Elasticsearch Java API for function_score query

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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/56d92aab-a4d7-4757-9441-f248c5296b3c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

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

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.
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?utm_medium=email&utm_source=footer
.
For more options, visit 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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CAKdsXoHBk2_PtoJkriZrvA-1B7vqB%3DhSLnaXOwFEkgeugsOZsQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

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
<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 <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?utm_medium=email&utm_source=footer
.
For more options, visit 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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/a03661cb-5310-42ca-996d-e2e137376bb1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

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

curl -XGET 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
<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 <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?utm_medium=email&utm_source=footer
.
For more options, visit 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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/311c8492-8e78-4188-847c-44d7d115b464%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

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 wrote:

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

curl -XGET 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
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.
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?utm_medium=email&utm_source=footer
.
For more options, visit 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.
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?utm_medium=email&utm_source=footer
.

For more options, visit 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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQCzs6fjav3SMMaf8vT79kMEccyC3-HWwK_wCjC8mYXQBw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

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
<javascript:>> wrote:

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

curl -XGET 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

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.
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?utm_medium=email&utm_source=footer
.
For more options, visit 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 <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?utm_medium=email&utm_source=footer
.

For more options, visit 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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/fb8ed6a8-541e-4a55-8a59-f100b48a2938%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.