1

I'm using Elastic Java API in Scala to delete a list of document, using their ID to delete them one at a time, no success for now. API works fine for other calls like SearchResponse.
My code looks like this :

var deleteResp : DeleteResponse = null

deleteResp = ElasticSearch.getClient()
      .prepareDelete(index, type, id)
      .get()

Same with :

deleteResp = ElasticSearch.getClient()
      .prepareDelete(index, type, id)
      .execute()
      .actionGet()

I also tried to catch Elastic response for debugging using this, but nothing shows up in stdout.

try{ \ previous code } 
catch {
    case e: Exception => {
    print("Failed deletion", e.getMessage)
    e.printStackTrace() }
}

Config :
- Scala 2.10.6
- Spark 1.6
- Elasticsearch 2.3.2

Thank you

8
  • 1
    Are you sure about your index, type and id? can you find the document with curl -XGET localhost:9200/index/type/id ? Commented Mar 29, 2018 at 8:16
  • Ok, and you're sure that your client is properly connected to your ES server? Commented Mar 29, 2018 at 8:32
  • Same for connectivity, deletion part is actually the last step of the code. Before that, in run multiple queries to get JSON responses and process them without trouble. Commented Mar 29, 2018 at 8:38
  • But what kind of response do you actually get in deleteResp ? Commented Mar 29, 2018 at 8:40
  • Thing is I don't know how to catch the response, the try/catch block does not return any stackTrace, and printing the deleteResp var gives org.elasticsearch.action.delete.DeleteResponse@5da55732 However when I directly send a DELETE command in Sense it's working fine. Commented Mar 29, 2018 at 9:03

1 Answer 1

1

I guess it's a pretty specific case but given the poor info on Java API usage, someone may find this case relevant.

Thank to Val and precise debugging I found the cause : Be very careful on the string format passed to the prepareSearch().

My ID, coming from a List, contained brackets that messed things up, the delete request was successful but on a wrong ID.

For details, think about using all available methods on request objects and double check each formatting :

var deletedId = deleteResp.getId()
var deletedType = deleteResp.getType()
var deletedIndex = deleteResp.getIndex()
var deletedShard = deleteResp.getShardInfo()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.