# Delete by query creating a new document in the index (ES 5.4)

**URL:** <https://discuss.elastic.co/t/delete-by-query-creating-a-new-document-in-the-index-es-5-4/87417>\
**Category:** Elasticsearch\
**Created:** [May 29, 2017, 8:37am UTC](https://discuss.elastic.co/t/delete-by-query-creating-a-new-document-in-the-index-es-5-4/87417 "2017-05-29T08:37:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Scott\_at\_skyscanner](https://avatars.discourse-cdn.com/v4/letter/s/71e660/32.png) [@Scott\_at\_skyscanner](https://discuss.elastic.co/u/Scott_at_skyscanner)\
**Post date:** [May 29, 2017, 8:37am UTC](https://discuss.elastic.co/t/delete-by-query-creating-a-new-document-in-the-index-es-5-4/87417/1 "2017-05-29T08:37:51Z")

</div>

I am testing out ElasticSearch 5.4 before upgrading our existing code base and getting strange behaviour when running a delete by query on a couple of indices - in every case it looks like a new document with id '\_delete\_by\_query' is being created:

```
09:30:13.822 [Test worker] DEBUG org.apache.http.headers - http-outgoing-0 >> POST /user-complaints-all/user-complaint/_delete_by_query HTTP/1.1
09:30:13.822 [Test worker] DEBUG org.apache.http.headers - http-outgoing-0 >> Content-Length: 123
09:30:13.822 [Test worker] DEBUG org.apache.http.headers - http-outgoing-0 >> Content-Type: application/json; charset=UTF-8
09:30:13.822 [Test worker] DEBUG org.apache.http.headers - http-outgoing-0 >> Host: localhost:9605
09:30:13.822 [Test worker] DEBUG org.apache.http.headers - http-outgoing-0 >> Connection: Keep-Alive
09:30:13.822 [Test worker] DEBUG org.apache.http.headers - http-outgoing-0 >> User-Agent: Apache-HttpClient/4.5.3 (Java/1.8.0_91)
09:30:13.822 [Test worker] DEBUG org.apache.http.headers - http-outgoing-0 >> Accept-Encoding: gzip,deflate
09:30:13.823 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 >> "POST /user-complaints-all/user-complaint/_delete_by_query HTTP/1.1[\r][\n]"
09:30:13.823 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 >> "Content-Length: 123[\r][\n]"
09:30:13.823 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 >> "Content-Type: application/json; charset=UTF-8[\r][\n]"
09:30:13.823 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 >> "Host: localhost:9605[\r][\n]"
09:30:13.823 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 >> "Connection: Keep-Alive[\r][\n]"
09:30:13.823 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 >> "User-Agent: Apache-HttpClient/4.5.3 (Java/1.8.0_91)[\r][\n]"
09:30:13.823 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 >> "Accept-Encoding: gzip,deflate[\r][\n]"
09:30:13.823 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 >> "[\r][\n]"
09:30:13.823 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 >> "{[\n]"
09:30:13.823 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 >> " "query" : {[\n]"
09:30:13.823 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 >> " "term" : {[\n]"
09:30:13.823 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 >> " "Date" : {[\n]"
09:30:13.823 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 >> " "value" : "2017-02-27",[\n]"
09:30:13.823 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 >> " "boost" : 1.0[\n]"
09:30:13.823 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 >> " }[\n]"
09:30:13.824 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 >> " }[\n]"
09:30:13.824 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 >> " }[\n]"
09:30:13.824 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 >> "}"
09:30:13.954 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 << "HTTP/1.1 201 Created[\r][\n]"
09:30:13.955 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 << "Location: /user-complaints-all/user-complaint/_delete_by_query[\r][\n]"
09:30:13.955 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 << "Content-Type: application/json; charset=UTF-8[\r][\n]"
09:30:13.955 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 << "Content-Encoding: gzip[\r][\n]"
09:30:13.955 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 << "Content-Length: 147[\r][\n]"
09:30:13.955 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 << "[\r][\n]"
09:30:13.955 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 << "[0x1f][0x8b][0x8][0x0][0x0][0x0][0x0][0x0][0x0][0x0]d[0x8b]A[0xe][0x2]![0x10][0x4][0xff]2g6Q[0x8f]|[0x86] [0xf4]F[0x92][0x11][0xd6][0x99][0xc1][0xb8][0xd9][0xec][0xdf][0x85][0x8b][0x17][0x8f][0xdd]UuP(5[0xe3]C[0x9e][0xba]B[0x96][0xd4][0x9e][0x1b][0xc7]RM[0x97][0xc8]L[0x8e][0x82][0xed][0x1b][0xfe][0xe8][0x4]%[0x8f];d0[0xc][0xe1][0xbe][0x87]W[0x87][0xec][0x13][0xbc]!ZZ%u$[0xd0][0xce]6[0xc4]$[0x88][0x86]<[0xb9]>[0xa2]d%[0x90]5[0x8b]L[0xfe][0xe6]H{JP][0xfb][0x98]#[c[0xe1]![0xfb][0xcb][0xe9]~[0xa5]7[0xe9]8[0xbf][0x0][0x0][0x0][0xff][0xff][0x3][0x0][0x82][0x92][0x99][0xb4][0xb1][0x0][0x0][0x0]"
09:30:13.956 [Test worker] DEBUG org.apache.http.headers - http-outgoing-0 << HTTP/1.1 201 Created
09:30:13.956 [Test worker] DEBUG org.apache.http.headers - http-outgoing-0 << Location: /user-complaints-all/user-complaint/_delete_by_query
09:30:13.956 [Test worker] DEBUG org.apache.http.headers - http-outgoing-0 << Content-Type: application/json; charset=UTF-8
09:30:13.956 [Test worker] DEBUG org.apache.http.headers - http-outgoing-0 << Content-Encoding: gzip
09:30:13.956 [Test worker] DEBUG org.apache.http.headers - http-outgoing-0 << Content-Length: 147

```

I'm using the latest JEST client to interact with ElasticSearch and the HTTP request looks correct to me but instead of deleting the target records, I get a new record in the index.

Any help would be greatly appreciated.

Thanks!

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [May 30, 2017, 1:03am UTC](https://discuss.elastic.co/t/delete-by-query-creating-a-new-document-in-the-index-es-5-4/87417/2 "2017-05-30T01:03:26Z")

</div>

Providing the request you are creating would be helpful.

Also take a look at the java rest client - [https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/index.html](https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/index.html)

---

<div class="post-metadata">

**Author:** ![Scott\_at\_skyscanner](https://avatars.discourse-cdn.com/v4/letter/s/71e660/32.png) [@Scott\_at\_skyscanner](https://discuss.elastic.co/u/Scott_at_skyscanner)\
**Post date:** [May 30, 2017, 7:38am UTC](https://discuss.elastic.co/t/delete-by-query-creating-a-new-document-in-the-index-es-5-4/87417/3 "2017-05-30T07:38:00Z")

</div>

I realised that the issue was that I was not loading the reindex plugin (I am using a manually created Node to do some testing against which I know is no longer supported). Creating the node with the plugin solved the problem.

---

<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:** [June 27, 2017, 7:38am UTC](https://discuss.elastic.co/t/delete-by-query-creating-a-new-document-in-the-index-es-5-4/87417/4 "2017-06-27T07:38:17Z")

</div>

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