我在ElasticSearch中找到了一个像
的函数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;"
}
}
]
}
}
ScoreFunctionBuilder
来实现“位置caluse”和
“价格caluse”,但我不知道如何用java api写"script_score"
和"script"
ScriptScoreFunctionBuilder. scriptFunction(String script,
Map<String, Object> params)
我该怎么办?Thx :)
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);
这就是全部
答案 0 :(得分:1)
以下是如何在java中实现scrip_ score功能
<example-component start="exampleData.star"
end="exampleData.end" *ngIf="exampleData.start" >
</example-component>