我想将elasticsearch用作搜索引擎。我正在将记录从mysql复制到elasticsearch,当我查询elasticsearch时,我想使用Elastic中的数据计算一个值并使用它对结果进行排序
我的索引如下:
{
"busquedas" : {
"aliases" : { },
"mappings" : {
"coche" : {
"properties" : {
"coeff_e" : {
"type" : "double"
},
"coeff_r" : {
"type" : "double"
},
"desc" : {
"type" : "string"
}
}
}
},
"settings" : {
"index" : {
"creation_date" : "1460116924258",
"number_of_shards" : "5",
"number_of_replicas" : "1",
"uuid" : "N6jhy_ilQmSb6og16suZ4g",
"version" : {
"created" : "2030199"
}
}
},
"warmers" : { }
}
}
我想计算每条记录的值
myCustomOrder = (coeff_e + coeff_r) * timestamp
并使用它对结果进行排序
{
"sort" : [
{ "myCustomOrder" : {"order" : "asc"}},
"_score"
],
"query" : {
"term" : { ... }
}
}
我知道我可以使用groovy来计算值,但是我只能使用它来过滤,如示例中所示
{
"from": 10,
"size": 3,
"filter": {
"script": {
"script": "doc['coeff_e'].value < 0.5"
}
}
}
在此先感谢您,我完全是Elasticsearch的新手:D
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句