作者:姿萱俊达俊宏 | 来源:互联网 | 2022-12-12 16:29
目前,在ES 5.6上,我们使用groovy内联脚本来获取给定文档中给定术语的tf,如 -
GET document/_search
{
"size": 114,
"query": {"terms": {
"doc_id": [1840, 2160]
}},
"script_fields": {
"tf": {
"script": {
"lang": "groovy",
"inline": "_index['text'][term_value].tf()",
"params": {
"term_value": "hello"
}
}
}
}
}
所以它回复我的回应 -
"hits": {
"total": 36,
"max_score": 1,
"hits": [
{
"_index": "document",
"_type": "sample",
"_id": "41707",
"_score": 1,
"fields": {
"tf": [
3
]
}
}]
但是在ES 6.0 groovy
支持下降之后,似乎脚本引擎是唯一的解决方案,而且由于缺乏对Elasticsearch类和内部行为的正确理解,很难弄清楚实现.
基于Scripting Engine文档,我需要实现
private static class MyExpertScriptEngine implements ScriptEngine {
@Override
public String getType() {
return "string";
}
@Override
public T compile(String scriptName, String scriptSource, ScriptContext context, Map params) {}
**What goes here?**
}
这个类的实现或其他一些方法来实现所需的输出将是很大的帮助.