简体   繁体   English

从Elasticsearch响应数组中删除对象

[英]Delete an object from an Elasticsearch response array

I'm trying to delete and object from my Elasticsearch result query, but this object persist whatever I do: 我正在尝试从Elasticsearch结果查询中删除和对象,但是无论我做什么,该对象都会保留:

Here is my code : 这是我的代码:

exports.searchUserByKeyWord = (req, res) => {
    User.search(byKeyWordQuery(req), geoDistance(), (err, users) => {
        if (err) requestError(res, err)
            let result = []
            for(let user of users.hits.hits) {
                delete user.address.full
                result.push(user)
            }
        sendJsonResponse(res, 200, result)
    })
}

Like you can see I'm using delete but it doesn't work, what I can't understand here is the fact that when I replace sendJsonResponse(res, 200, result) with sendJsonResponse(res, 200, result[0].address.full) I found out that this address got successfully deleted, but when I test my API with Postman without adding result[0].address.full the address full field is still there ... 就像您看到的那样,我使用的是delete,但不起作用,我在这里无法理解的事实是,当我用sendJsonResponse(res, 200, result[0].address.full)替换sendJsonResponse(res, 200, result)sendJsonResponse(res, 200, result[0].address.full)我发现此地址已成功删除,但是当我用邮递员测试我的API而不添加result[0].address.full ,address full字段仍然存在...

are you reindexing your elasticsearch data after you delete? 删除后要重新索引您的Elasticsearch数据吗? the indexed record may persist even though you have removed the document from disk 即使您从磁盘上删除了文档,索引记录也可能会持续存在

more on this can be read @ https://www.elastic.co/guide/en/elasticsearch/guide/current/update-doc.html 有关更多信息,请阅读@ https://www.elastic.co/guide/en/elasticsearch/guide/current/update-doc.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM