Why is my _delete_by_query being ignored?

I understand that _delete_by_query is now added to core, and no longer requires a plugin.

Using org.elasticsearch:elasticsearch:5.5.2, I am starting a org.elasticsearch.node.Node with:

public void before() throws Exception {
    Settings settings = Settings.builder()
            .put(NetworkModule.HTTP_TYPE_KEY, Netty4Plugin.NETTY_HTTP_TRANSPORT_NAME)
            .put(NetworkModule.TRANSPORT_TYPE_KEY, Netty4Plugin.NETTY_TRANSPORT_NAME)
            .put(NetworkModule.HTTP_ENABLED.getKey(), true)
            .put(HttpTransportSettings.SETTING_HTTP_PORT.getKey(), port)
            .put("path.home", path.getAbsolutePath())
            .build();
    node = new MyNode(InternalSettingsPreparer.prepareEnvironment(settings, null), Collections.singleton(Netty4Plugin.class)).start();
}

Then, I create a trivial index, add a document, query for the document, and then try to delete. ES keeps treating "_delete_by_query" like an id or a type mapping, not an API endpoint. What am I doing wrong?

When running the same version of ES as an application (ie. not from Java code), the endpoint works as expected.

$ curl -XPUT 'localhost:59200/foo?pretty' -H 'Content-Type: application/json' -d'
> {
>   "mappings": {
>     "bar": {
>       "properties": {
>         "baz": {
>           "type": "keyword"
>         }
>       }
>     }
>   }
> }
> '
{
  "acknowledged" : true,
  "shards_acknowledged" : true
}

$ curl -XPUT 'localhost:59200/foo/bar/1?pretty' -H 'Content-Type: application/json' -d'{"baz":"lol"}'
{
  "_index" : "foo",
  "_type" : "bar",
  "_id" : "1",
  "_version" : 1,
  "result" : "created",
  "_shards" : {
    "total" : 2,
    "successful" : 1,
    "failed" : 0
  },
  "created" : true
}

$ curl 'localhost:59200/foo/bar/_search?pretty'
{
  "took" : 2,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 1,
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "foo",
        "_type" : "bar",
        "_id" : "1",
        "_score" : 1.0,
        "_source" : {
          "baz" : "lol"
        }
      }
    ]
  }
}

$ curl 'localhost:59200/foo/bar/_search?pretty' -d'
> {
>     "query": {
>       "match": {
>         "baz": "lol"
>       }
>     }
> }
> '
{
  "took" : 3,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 1,
    "max_score" : 0.2876821,
    "hits" : [
      {
        "_index" : "foo",
        "_type" : "bar",
        "_id" : "1",
        "_score" : 0.2876821,
        "_source" : {
          "baz" : "lol"
        }
      }
    ]
  }
}

$ curl -XPOST 'localhost:59200/foo/bar/_delete_by_query?pretty' -d'
> {
>     "query": {
>       "match": {
>         "baz": "lol"
>       }
>     }
> }
> '
{
  "_index" : "foo",
  "_type" : "bar",
  "_id" : "_delete_by_query",
  "_version" : 1,
  "result" : "created",
  "_shards" : {
    "total" : 2,
    "successful" : 1,
    "failed" : 0
  },
  "created" : true
}

$ curl -XPOST 'localhost:59200/foo/_delete_by_query?pretty' -d'
> {
>     "query": {
>       "match": {
>         "baz": "lol"
>       }
>     }
> }
> '
{
  "error" : {
    "root_cause" : [
      {
        "type" : "invalid_type_name_exception",
        "reason" : "Document mapping type name can't start with '_', found: [_delete_by_query]"
      }
    ],
    "type" : "invalid_type_name_exception",
    "reason" : "Document mapping type name can't start with '_', found: [_delete_by_query]"
  },
  "status" : 400
}

Starting a node in Java is not supported.
So you are missing some modules here IMO.

Well, this is just for testing. :smiley:

Which modules are missing and is it possible to add them?

Alternatively, is there another way to fire up an in-memory ES instance for unit/integration testing?

Which modules are missing?

and is it possible to add them?

No. I don't think it's possible. AFAIK they are not published as separate artifacts and are bundled in the final distribution.

I wrote some ideas in In memory testing with RestHighLevelClient - #6 by dadoonet.

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