Does _delete_by_query need a plugin or not? ES version 5.5

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?

FYi 5.X has been EOL for quite some time, you should really upgrade as a matter of urgency.

The docs show this as an example, with no type defined;

POST twitter/_delete_by_query
{
  "query": { 
    "match": {
      "message": "some message"
    }
  }
}

If that's not working, what does your query look like?

Thanks for the reply, as well as version change suggestion, I'll look into that!

So, my query is like this:

POST <index_name>/_delete_by_query?routing=<parent_type>
{
  "query" : {
    "bool" : {
      "must_not" : [
        {
          "has_parent" : {
            "query" : {
              "match_all" : {
                "boost" : 1.0
              }
            },
            "parent_type" : <parent_type>,
            "score" : false,
            "ignore_unmapped" : false,
            "boost" : 1.0
          }
        }
      ],
      "disable_coord" : false,
      "adjust_pure_negative" : true,
      "boost" : 1.0
    }
  }
}

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.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.