【发布时间】:2018-11-09 08:57:39
【问题描述】:
是否有任何方法可以在 Elasticsearch 数学运算中执行如下所述的 SQL 运算?如果是,执行此类搜索操作的最佳方式是什么?
select * from products where price + 50 > 20
【问题讨论】:
标签: elasticsearch math search
是否有任何方法可以在 Elasticsearch 数学运算中执行如下所述的 SQL 运算?如果是,执行此类搜索操作的最佳方式是什么?
select * from products where price + 50 > 20
【问题讨论】:
标签: elasticsearch math search
使用无痛脚本查询 (https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-script-query.html) 是可行的。
试试这个:
GET /products/_search
{
"query": {
"bool" : {
"must" : {
"script" : {
"script" : {
"source": "(doc['price'].value + 50) > 20",
"lang": "painless"
}
}
}
}
}
}
类似行为的预处理语句可以这样完成:
GET /products/_search
{
"query": {
"bool" : {
"must" : {
"script" : {
"script" : {
"source": "(doc['price'].value + params.foo) > params.bar",
"lang": "painless",
"params" : {
"foo" : 50,
"bar" : 20
}
}
}
}
}
}
}
【讨论】: