# Delete by query API invalid type name exception

**URL:** <https://discuss.elastic.co/t/delete-by-query-api-invalid-type-name-exception/169420>\
**Category:** Elasticsearch\
**Created:** [February 21, 2019, 1:43pm UTC](https://discuss.elastic.co/t/delete-by-query-api-invalid-type-name-exception/169420 "2019-02-21T13:43:31Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![squash\_nut](https://avatars.discourse-cdn.com/v4/letter/s/9f8e36/32.png) [@squash\_nut](https://discuss.elastic.co/u/squash_nut)\
**Post date:** [February 21, 2019, 1:43pm UTC](https://discuss.elastic.co/t/delete-by-query-api-invalid-type-name-exception/169420/1 "2019-02-21T13:43:32Z")

</div>

I am using the high level rest client (6.6.0) and an embedded node (for system testing my code). I know the embedded node is not supported but this is not a "live" system. It is a node that is spun up in my system tests then destroyed at the end.

I can start the node, create an index and index a number of documents.

I then try and run a "delete\_by\_query" command (using the low level client as the high level client is adding unsupported query parameters).

A CURL example of my request is

`curl -X POST "http://localhost:9201/my-index/_delete_by_query" -H 'Content-Type: application/json' -d ' {"query":{"match_all":{}}} '`

I get an error response with the exception as "invalid\_type\_name\_exception" and the reason being "Document mapping type cannot start with '\_' found: [\_delete\_by\_query]"

Interesting if I change the CURL url to "[http://localhost:9201/my-index/doc/\_delete\_by\_query](http://localhost:9201/my-index/doc/_delete_by_query)" where "doc" is my type, then the request runs but creates a document in the index.

This seems to be the same as this issue [https://discuss.elastic.co/t/delete-by-query-error-invalid-type-name-exception/119629](https://discuss.elastic.co/t/delete-by-query-error-invalid-type-name-exception/119629) but I didn't think I need to install a plugin for "delete\_by\_query"?

Can anyone help me with where I'm going wrong please?

---

<div class="post-metadata">

**Author:** ![squash\_nut](https://avatars.discourse-cdn.com/v4/letter/s/9f8e36/32.png) [@squash\_nut](https://discuss.elastic.co/u/squash_nut)\
**Post date:** [February 21, 2019, 2:20pm UTC](https://discuss.elastic.co/t/delete-by-query-api-invalid-type-name-exception/169420/2 "2019-02-21T14:20:35Z")

</div>

So on doing some further research I can see thats its most likely that delete\_by\_query is unavailable in the embedded node. Can anyone confirm this?

Its a shame the embedded node is no longer supported, it makes system testing your code much more difficult.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 21, 2019, 2:25pm UTC](https://discuss.elastic.co/t/delete-by-query-api-invalid-type-name-exception/169420/3 "2019-02-21T14:25:59Z")

</div>

It's because delete by query is part of a module.

As you know you can not run elasticsearch embedded as this [blog post](https://www.elastic.co/blog/elasticsearch-the-server) says.

Note that to run integration tests (not unit tests) you would probably prefer running that in something close to a production environment, like a real elasticsearch server instance. I shared some ideas about integration testing in this thread: [In memory testing with RestHighLevelClient](https://discuss.elastic.co/t/in-memory-testing-with-resthighlevelclient/106196/6)

Also this sample project shows how to use Elasticsearch Test Classes:

> **[joel-costigliola/elastic-search-test](https://github.com/joel-costigliola/elastic-search-test)**
>
> ESIntegTestCase example. Contribute to joel-costigliola/elastic-search-test development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![squash\_nut](https://avatars.discourse-cdn.com/v4/letter/s/9f8e36/32.png) [@squash\_nut](https://discuss.elastic.co/u/squash_nut)\
**Post date:** [February 21, 2019, 2:47pm UTC](https://discuss.elastic.co/t/delete-by-query-api-invalid-type-name-exception/169420/4 "2019-02-21T14:47:36Z")

</div>

Hi David

I will take a look further into the elasticsearch test cases as that looks interesting.

I like to write integration tests around an embedded client in my code to give me a level of assurance before testing against other environments. It gives quicker feedback IMO.

Thanks for your reply and the information

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 21, 2019, 3:34pm UTC](https://discuss.elastic.co/t/delete-by-query-api-invalid-type-name-exception/169420/5 "2019-02-21T15:34:41Z")

</div>

I updated the content of [In memory testing with RestHighLevelClient](https://discuss.elastic.co/t/in-memory-testing-with-resthighlevelclient/106196/6)...

I'm now using myself Docker from maven as shown here:

> <https://github.com/dadoonet/fscrawler/blob/e15dddf72b1ed094dad279d492e4e0314f73683f/pom.xml#L241-L289>

---

<div class="post-metadata">

**Author:** ![squash\_nut](https://avatars.discourse-cdn.com/v4/letter/s/9f8e36/32.png) [@squash\_nut](https://discuss.elastic.co/u/squash_nut)\
**Post date:** [February 27, 2019, 5:36pm UTC](https://discuss.elastic.co/t/delete-by-query-api-invalid-type-name-exception/169420/6 "2019-02-27T17:36:26Z")

</div>

So i set up my code to use the Elasticsearch test classes and the nodes that they fire up. However i still get the same errors when running delete by query.

Is this the same problem as when using an embedded node and the module is not loaded?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 27, 2019, 6:11pm UTC](https://discuss.elastic.co/t/delete-by-query-api-invalid-type-name-exception/169420/7 "2019-02-27T18:11:02Z")

</div>

Yes. Probably the same problem.  
As I said for integration tests I prefer to run a real node with all features.

---

<div class="post-metadata">

**Author:** ![squash\_nut](https://avatars.discourse-cdn.com/v4/letter/s/9f8e36/32.png) [@squash\_nut](https://discuss.elastic.co/u/squash_nut)\
**Post date:** [February 27, 2019, 8:11pm UTC](https://discuss.elastic.co/t/delete-by-query-api-invalid-type-name-exception/169420/8 "2019-02-27T20:11:03Z")

</div>

Such a shame this isn't available...

What i would find really useful about having an embedded node is i can write a system level test for my code (using junit for example) which tests my code against a lifelike system without having to move out of my IDE. Then I can TDD my code to make that test pass, using all the features offered within the IDE (debugging etc). Once that passes i can then move to further integration testing using other environments.

Is this pattern possible using the docker for maven solution?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 27, 2019, 10:09pm UTC](https://discuss.elastic.co/t/delete-by-query-api-invalid-type-name-exception/169420/9 "2019-02-27T22:09:45Z")

</div>

That's what I'm doing and what I proposed in my previous answer.  
But you can't debug elasticsearch itself. Which I don't think you need. I never needed to debug a server.

---

<div class="post-metadata">

**Author:** ![squash\_nut](https://avatars.discourse-cdn.com/v4/letter/s/9f8e36/32.png) [@squash\_nut](https://discuss.elastic.co/u/squash_nut)\
**Post date:** [February 28, 2019, 8:14am UTC](https://discuss.elastic.co/t/delete-by-query-api-invalid-type-name-exception/169420/10 "2019-02-28T08:14:03Z")

</div>

I can see that would work, but to me it brings in an external dependency on Docker into my development process, and I'm running on Windows which makes things more complicated.

Also if you were pushing those tests through a CI pipepline your build agents would then also need Docker.

Is there anyway I can identify the module that provides delete\_by\_query and load it? Could I just find the plugin version of it and load that?

Thanks

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 28, 2019, 8:33am UTC](https://discuss.elastic.co/t/delete-by-query-api-invalid-type-name-exception/169420/11 "2019-02-28T08:33:57Z")

</div>

I think that jars for modules are not published anywhere so you would need to manually build them, add to your repository manager and use.

Speaking of CI, you can also install Docker on the machine where your ci is running, have an elasticsearch service running somewhere in your network or use an external service like [cloud.elastic.co](http://cloud.elastic.co).

This is what I tried to showcase there:

> **[dadoonet/elasticsearch-integration-tests](https://github.com/dadoonet/elasticsearch-integration-tests)**
>
> Demo project for elasticsearch integration testing with Docker - dadoonet/elasticsearch-integration-tests

(There are multiple branches - look at the last one. Note that the code is a bit old).

---

<div class="post-metadata">

**Author:** ![squash\_nut](https://avatars.discourse-cdn.com/v4/letter/s/9f8e36/32.png) [@squash\_nut](https://discuss.elastic.co/u/squash_nut)\
**Post date:** [February 28, 2019, 1:05pm UTC](https://discuss.elastic.co/t/delete-by-query-api-invalid-type-name-exception/169420/12 "2019-02-28T13:05:47Z")

</div>

I had a break through! By adding the reindex plugin to the node configuration this then makes the delete\_by\_query REST call work.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 28, 2019, 1:23pm UTC](https://discuss.elastic.co/t/delete-by-query-api-invalid-type-name-exception/169420/13 "2019-02-28T13:23:26Z")

</div>

Oh I see. As it might be required by the High Level Rest Client for the Reindex API, it is also published.  
I don't know TBH how long it will stay published. If the HLClient only uses at some point new classes for reindex request and response objects, I think it will not be published anymore. But that's just my thoughts.

I'd not rely on this for the future.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 28, 2019, 1:23pm UTC](https://discuss.elastic.co/t/delete-by-query-api-invalid-type-name-exception/169420/14 "2019-03-28T13:23:44Z")

</div>

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