how to write elasticsearch script_score in java api -


i find function in elasticsearch like

get /_search {   "function_score": {     "functions": [       { ...location clause... },        { ...price clause... },        {         "script_score": {           "params": {              "threshold": 80,             "discount": 0.1,             "target": 10           },           "script": "price  = doc['price'].value; margin = doc['margin'].value;           if (price < threshold) { return price * margin / target };           return price * (1 - discount) * margin / target;"          }       }     ]   } } 
  • i use scorefunctionbuilder achive "location caluse" , "price caluse" ,but not know how write "script_score" , "script" java api
  • the es version in project 2.2.0 , use java api achieve function
  • but can not find api scriptscorefunctionbuilder. scriptfunction(string script, map<string, object> params) how can do? thx :)
  • finally figure out how write using jd-jui check "elasticsearch.jar" file.

ex:

map<string, object> params = new hashmap<>();     params.put("num1", 10);     params.put("num2", 4);      string inlinescript = "doc['score'].value * num1 * num2";      script script = new script(script, scripttype.inline, "groovy", params);      scriptscorefunctionbuilder scriptbuilder = scorefunctionbuilders.scriptfunction(ss); 

that's

here how can implement scrip_ score function in java

map<string, object> params = new hashmap<>();                    params.put("paramname1", "paramval1") params.put("paramname2", "paramval2");  string script = "price  = doc['price'].value; margin = doc['margin'].value;       if (price < threshold) { return price * margin / target };       return price * (1 - discount) * margin / target;" xcontentbuilder builder =                      new scriptscorefunctionbuilder()                     .script(script)                     .lang("groovy")                     .params(params)                     .toxcontent(xcontentbuilder, params); 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -