从 mongoDB 中删除记录时,elastics 未与其同步
When deleting records from mongoDB, elastics is not syncing with it
有人请告诉我为什么不同步我的 mogoosastic 和 mongodb?
当我从 mongoDB 中删除记录时,仍然可以看到记录,直到服务器重新启动。这是我的搜索功能
exports.search = function (req, res) {
if (!req.query.q) return res.status(400).send('No Query Provided')
log.error(req.query.q)
var query = {
query_string: {
filtered: {
query: {
multi_match: {query: req.query.q,}
},
filter: {term: {isDeleted: false}
}
}
}
}
User.search(query, (err, results) => {
if (err) return handleError1(res, err)
var ret = _.map(results.hits.hits, result => ({
userID: result._id,
_score: result._score,
name: result._source.name,
loc: result._source.loc,
info: result._source.info,
images: result._source.images,
}))
return res.send(ret)
})
}
这是我的架构声明
isDeleted: {type: Boolean, required: true, default: false, es_indexed: true}
这段代码有什么问题...
我添加了这行代码,一切正常
.then(groups => {
return User.findById(uid).exec()
})
.then(user => {
let email = user.credentials.loginEmail + '_' + moment().format('YYYYMMDDEHHmmss')
if(app.get('env') === 'localtest') {
email = user.credentials.loginEmail + '_deleted'
}
user.credentials.loginEmail = email;
user.isDeleted = true;
user.updated.at = new Date();
user.save()
.then(user_ =>{
user.sendInfoUpdate()
return res.status(204).send()
})
.catch(err => {
return handleError(res, err)
})
})
.catch(err => {
return handleError(res, err)
})
有人请告诉我为什么不同步我的 mogoosastic 和 mongodb? 当我从 mongoDB 中删除记录时,仍然可以看到记录,直到服务器重新启动。这是我的搜索功能
exports.search = function (req, res) {
if (!req.query.q) return res.status(400).send('No Query Provided')
log.error(req.query.q)
var query = {
query_string: {
filtered: {
query: {
multi_match: {query: req.query.q,}
},
filter: {term: {isDeleted: false}
}
}
}
}
User.search(query, (err, results) => {
if (err) return handleError1(res, err)
var ret = _.map(results.hits.hits, result => ({
userID: result._id,
_score: result._score,
name: result._source.name,
loc: result._source.loc,
info: result._source.info,
images: result._source.images,
}))
return res.send(ret)
})
}
这是我的架构声明
isDeleted: {type: Boolean, required: true, default: false, es_indexed: true}
这段代码有什么问题...
我添加了这行代码,一切正常
.then(groups => {
return User.findById(uid).exec()
})
.then(user => {
let email = user.credentials.loginEmail + '_' + moment().format('YYYYMMDDEHHmmss')
if(app.get('env') === 'localtest') {
email = user.credentials.loginEmail + '_deleted'
}
user.credentials.loginEmail = email;
user.isDeleted = true;
user.updated.at = new Date();
user.save()
.then(user_ =>{
user.sendInfoUpdate()
return res.status(204).send()
})
.catch(err => {
return handleError(res, err)
})
})
.catch(err => {
return handleError(res, err)
})