So I've seen this post from way before in 2015 saying that delete by query is supported through a plugin delete-by-query. This was for the Elasticsearch version 2.0.0. However, there's a newer post which says that now this function is inside the core API, and no plugin is needed. If I got it correctly, newer update is valid from version 5.0 onwards.
Now, my problem is that Elasticsearch does not recognise _delete_by_query function, and inserts a document with that function name as its ID - _id: "_delete_by_query". This happens if I run:
POST <index_name>/<mapping_name>/_delete_by_query
{
"query": { ... }
}
If I try to call it without the specified mapping:
POST <index_name>/_delete_by_query
{
"query": { ... }
}
I get an error:
{
"type": "invalid_type_name_exception",
"reason": "Document mapping type name can't start with '_', found: [_delete_by_query]"
}
This post mentions that the error happens if the plugin is needed, and ES cannot recognise the _delete_by_query function. I'm running Elasticsearch 5.5.2, so how could that be possible? If this is not the case, what causes then this behaviour?
I've tried both that and POST <index_name>/<child_type>/_delete_by_query?routing=<parent_type> with the same query. When child type is specified, the record is inserted in the ES with _id="_delete_by_query", but when I leave it out I get that invalid_type_name_exception.
However, I did decent amount of digging and found this topic that seems to be related to my issue. I indeed run an embedded instance for testing purposes, and _delete_by_query is not supported there. The workaround mentioned was to include reindex plugin in the elasticsearch configuration. I haven't been able to make that workaround work, but in the end, as the last comment on that thread says, it's not a reliable solution.
In the end, I'll most likely drop this unit test that I had trouble with, and only rely on the integration test that uses a standalone elasticsearch server, which does support _delete_by_query.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.