使用nodejs作为弹性搜索的后端的日期范围



我有以下查询:

router.get('/date', (req, res)=>{
let query = {
index: 'decisions',
size: 5000,   
from: 0,
body:{
query:{
filtered:{
filter:{
bool:{
must:[{
"range": {
"Date_Lecture": {
"gt": "2019-04-04",
"lt": "2019-04-06"
}
}
}]
}
}
}
}
},
}
if(req.query.decisions) query.q = `*${req.query.decisions}`
client.search(query)
.then(resp=>{
return res.status(200).json({
decisions: resp.hits
})
.catch(err=>{
console.log(500).json({
msg:'Error',
err
})
})
})})

我想从弹性中获取那些在规定日期范围内的记录,但它显示了一个错误,说它不知道过滤的内容,如果我删除了过滤的内容;然后它显示另一个错误,说明它不知道过滤器以及我是否单独使用了范围;显示另一个错误,表示它不知道range关键字。

root_cause: [
{
type: 'parsing_exception',
reason: 'unknown query [filtered]',
line: 1,
col: 22
}
],

filtered查询早已不复存在(自ES 5.0以来(,您应该将查询更改为:

body:{
query:{
bool:{
filter:[{
"range": {
"Date_Lecture": {
"gt": "2019-04-04",
"lt": "2019-04-06"
}
}
}]
}
}
},

最新更新