Using deleteByQuery() in the Javascript API I would like to delete some documents from an index called people
.
It might be important to note that this is version 5.1 in AWS Elastic Search Service.
The index mapping looks like this:
"people": {
"mappings": {
"person": {
"properties": {
"name": {
"type": "string"
},
"parent_id": {
"type": "long"
},
"query": {
"properties": {
"match": {
"properties": {
"parent_id": {
"type": "long"
}
}
},
"term": {
"properties": {
"parent_id": {
"type": "long"
}
}
}
}
}
}
}
}
}
And a search query that is structured as follows:
query: {
term: {
parent_id: 1
}
}
Responds with:
"hits": {
"total": 1,
"max_score": 10.135444,
"hits": [
{
"_index": "people",
"_type": "person",
"_id": "AVp6EDRVm933W5mwl4O9",
"_score": 10.135444,
"_source": {
"name": "Bob",
"parent_id": 1
}
}
]
}
So then using the documentation for the JS API I have created the following:
const elasticsearch = require('elasticsearch')
function deletePeople (parentId) {
new elasticsearch
.Client({ host: 'es.host.domain' })
.deleteByQuery({
index: 'people',
type: 'person',
body: {
query: {
term: {
parent_id: parentId
}
}
}
}, function afterDeletingPeople (error, response) {
if (error) {
return console.log("deletePeople :: Error :: ", error);
}
else {
return console.log("deletePeople :: Response :: ", response);
}
});
};
deletePeople(1);
Which gives a response like:
info: deletePeople :: Response :: { _index: 'people',
_type: 'person',
_id: '_delete_by_query',
_version: 30,
_shards: { total: 2, successful: 1, failed: 0 },
created: false }
And that looks hopeful but no people are actually removed from the index. I tried to use match
instead of term
in the query but that does the same thing.
Could anyone suggest where I have gone wrong here with this as currently my function deletes no people? TIA!