使用 nodejs 作为弹性搜索后端的日期范围
Date range using nodejs as backend with elastic search
我有以下查询:
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
})
})
})})
我想从 elastic 中获取在指定日期范围内的那些记录,但它显示一个错误,说它不知道被过滤的,如果我删除了被过滤的;然后它会显示另一个错误,说明它不知道过滤器,如果我单独使用范围;显示另一个错误,说它不知道范围关键字。
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"
}
}
}]
}
}
},
我有以下查询:
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
})
})
})})
我想从 elastic 中获取在指定日期范围内的那些记录,但它显示一个错误,说它不知道被过滤的,如果我删除了被过滤的;然后它会显示另一个错误,说明它不知道过滤器,如果我单独使用范围;显示另一个错误,说它不知道范围关键字。
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"
}
}
}]
}
}
},