简体   繁体   中英

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:

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 ...

are you reindexing your elasticsearch data after you delete? 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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