【发布时间】:2016-11-02 14:24:12
【问题描述】:
我在 ES2.3 中有一个文件的映射如下
"move_in_ts": {
"type": "integer"
}
"move_out_ts": {
"type": "integer"
}
Sample document stores data as follows:
"move_in_ts": [
1475280000,
1475539200,
1475712000,
1475884800,
1477008000,
1477785600
]
我的 DSL 查询中有一个脚本(试图在该数组中查找一个整数)
"script": "if(doc['move_in_ts'] && doc['move_in_ts'].values.contains('1475280000')){return 200;}"
也试过这个:
"script": "if(doc['move_in_ts'] && doc['move_in_ts'].contains('1475280000')){return 200;}"
也试过这个:
"script": "if(doc['move_in_ts'] && doc['move_in_ts'].contains(1475280000)){return 200;}"
也试过这个:
"script": "if(doc['move_in_ts'] && doc['move_in_ts'].values.contains(1475280000)){return 200;}"
但在上述所有情况下,我都会收到以下错误:
"reason": {
"type": "null_pointer_exception",
"reason": null
}
这个字段可能在少数文档中根本不存在(我不能在我的用例中使用过滤器,我只需要在脚本中使用它)
我做错了什么或如何让它发挥作用?
【问题讨论】:
-
是 'move_in_ts' 嵌套字段吗?
-
我无法重现该问题。你能发布你的整个查询吗?你的索引很大吗?
-
不,它不是嵌套字段
-
@ChintanShah25 不,我的索引很小。哪个特定脚本适合您?
-
@ChintanShah25 这是我正在使用的真实脚本。
"functions": [{ "script_score": { "script": "if (doc['move_in_ts'] && doc['move_out_ts']) {return per_day_boost * ( [ doc['move_in_ts'], doc['move_out_ts'] ].transpose().find { av_start, av_out -> av_start <= desired_in_ts && av_out >= desired_out_ts }[0] - desired_in_ts).abs()/86400}; return 0;", "params": { "per_day_boost": -175, "desired_in_ts": 1478131200, "desired_out_ts": 1494547200 } } }]
标签: elasticsearch elasticsearch-2.0 elasticsearch-dsl