我只需要从 ES 中的 _score 获取一些字段。
例如这样:创建我自己的json-object并返回它,或者只返回特定的值(但我真的不明白怎么做)
{
"script_fields": {
"total_goals": {
"script": {
"lang": "painless",
"inline": "if ((params._source.f_data & 3) == 0) {return params.tee;} else {return false;}",
"params": {
"tee": {
"f_data": params._source.f_data,
"s_data": params._source.s_data,
"text": params._source.text,
}
}
}
}
文档:
$ curl -XGET "$ES_URL/please/_search?pretty"
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "please",
"_type" : "_doc",
"_id" : "pleaseworkforme14",
"_score" : 1.0,
"_source" : {
"_class" : "com.example.test.ind.info.ElasticData",
"f_data" : "123",
"s_data" : "Everyone4",
"text" : "Blue\n"
}
}
]
}
}
PS:脚本中的括号可能放置不正确