1

I have some custom data(let's call Camera) in my ElasticSearch, the data showed in Kibana is like

enter image description here

And I tried to delete data by Query according to the accepted answer in this article ElasticSearch Delete by Query, my code is like

String query = "{\"Name\":\"test Added into Es\"}";
DeleteByQuery delete = new DeleteByQuery.Builder(query).addIndex(this._IndexName).addType(this._TypeName).build();

JestResult deleteResult = this._JestClient.execute(delete);

And the result is 404 Not Found.

Its obvious that there exist one Camera data in ElasticSearch which Name match the query, so I believe the 404 is caused by other reason.

Did I do anything wrong? Should I change the query string?

Nkosi
  • 235,767
  • 35
  • 427
  • 472
Alanight
  • 353
  • 2
  • 8
  • 23

1 Answers1

1

The query needs to be a real query, not a partial document

Try with this instead

String query = "{\"query\": { \"match\": {\"Name\":\"test Added into Es\"}}}";
Val
  • 207,596
  • 13
  • 358
  • 360
  • Can you share the full error please? and also which version of ES you're using – Val Jun 02 '17 at 08:34
  • Sure! The full content is this `{"found":false,"_index":"cameras","_type":"camera","_id":"_query","_version":1,"result":"not_found","_shards":{"total":2,"successful":1,"failed":0}}`. And I'm using ElasticSearch 5.4.0. – Alanight Jun 02 '17 at 08:37
  • Ok I see the problem. Jest uses the `_query` endpoint which was the endpoint used by the Delete by query plugin back in ES 2.x. From ES 5 onwards, the delete by query feature has made it into the core and the endpoint is now named `_delete_by_query`. That [change has been made recently](https://github.com/searchbox-io/Jest/issues/434) in Jest and will soon be released – Val Jun 02 '17 at 08:45
  • 1
    So you have a few options: 1) downgrade to ES 2.4, 2) wait until the new Jest gets released or 3) checkout the Jest master branch and build it yourself. – Val Jun 02 '17 at 08:47
  • Sorry for responding so lately... I didn't search afterwards, because building it by myself is quite impossible for me to achieve, and also I transfer my work on another part, so I didn't work on this issue anymore. But still very appreciate for your information and suggestions, hope there would be a way to solve(hopefully provided by JEST) afterwards. Thanks! – Alanight Aug 18 '17 at 08:35