elasticsearch - Elasticsearch Painless 获取基于 Doc 值的动态参数
问题描述
在 NodeJS ES 客户端中,我试图传入一个由带有数字值的 id 键入的对象,并将其用于在我的 ES 查询中进行排序。
但是,我不断收到异常。是否可以根据文档中的值获取参数?
const res = await client.search({
index: 'some_index',
size,
from: 0,
body: {
sort: {
_script: {
type: 'number',
script: {
lang: 'painless',
source: "params.get(doc['id'].value)",
params: {
'some-id': 10,
'some-other-id': 3,
},
},
order: 'asc',
},
},
},
})
{
type: 'script_exception',
reason: 'runtime error',
script_stack: [
"params.get(doc['id'].value)",
" ^---- HERE"
],
script: "params.get(doc['id'].value)",
lang: 'painless'
}
解决方案
推荐阅读
- batch-file - 使用批处理文件在启动时启动 selenium slave
- go - 数据存储的 Go 接口,两种实现
- haskell - 我应该让我的 Haskell 模块默认安全吗?
- python - 将 python 数据结构传递给部署在 R 中的 MS R Server 模型
- ruby-on-rails - Rails 5:使用 config.eager_load=true 的 rails 生产失败,而 gem 'gem_name', require: false
- python - Python:求解具有复杂初始条件的二阶微分方程
- typescript - 如何访问角度 5 上的共享网络文件夹图像 - 不允许加载本地资源
- scala - 在 Scala 中制作列表的正确方法是什么?
- html - CSS - 悬停在 li a
- jquery - 为什么 removeClass() 有效但 hasClass() 无效?