Reindexing using Java Client - What happens when one or both of the index do not exist

What happens when one or both of the index do not exist if we do reindexing using Java Client? When I tested on local, it completes successfully without throwing exception.

How does one test if an index already exists or not?

I am new to Elasticsearch, any help would be really appreciated. Thanks :wave:

Welcome!

What does your code look like?

1 Like

I am using the RestHighLevelClient from ES Java REST Client to call the reindex method. I can see after the reindex that the total number of documents proccessed using the BulkScrollByResponse.getTotal().

Could you share the piece of code you are using please?

What is your elasticsearch version?

By the way, you should now switch to the new official Java Client.

1 Like

This is the skeleton code of what I am doing:

try {
    ReindexRequest request = new ReindexRequest().setSourceIndices(sourceIndex).setDestIndex(desIndex);
    BulkByScrollResponse response = restHighLevelClient.reindex(request, RequestOptions.DEFAULT);
} catch (Exception ex) {
    // do stuff
}

I except to get an exception if either of the indices targetIndex and/or sourceIndex are invalid/don't exist.

You did not tell which version you are using, but with a simple test on 8.8 in Kibana dev console:

POST /_reindex
{
  "source": {
    "index": "doesnotexist"
  },
  "dest": {
    "index": "foo"
  }
}

I'm getting a 404 error:

{
  "error": {
    "root_cause": [
      {
        "type": "index_not_found_exception",
        "reason": "no such index [doesnotexist]",
        "resource.type": "index_or_alias",
        "resource.id": "doesnotexist",
        "index_uuid": "_na_",
        "index": "doesnotexist"
      }
    ],
    "type": "index_not_found_exception",
    "reason": "no such index [doesnotexist]",
    "resource.type": "index_or_alias",
    "resource.id": "doesnotexist",
    "index_uuid": "_na_",
    "index": "doesnotexist"
  },
  "status": 404
}

I'd expect the same to happen in the Java Client. I just checked it with the new java client:

try {
  client.reindex(rr -> rr.source(s -> s.index("does-not-exists")).dest(d -> d.index("foo")));
} catch (ElasticsearchException e) {
  logger.info("Got error {}", e.response());
}

This gives:

12:05:21,952 INFO  [f.p.t.e.h.EsClientIT] Got error ErrorResponse: {"error":{"index_uuid":"_na_","index":"does-not-exists","resource.type":"index_or_alias","resource.id":"does-not-exists","type":"index_not_found_exception","reason":"no such index [does-not-exists]","root_cause":[{"index_uuid":"_na_","index":"does-not-exists","resource.type":"index_or_alias","resource.id":"does-not-exists","type":"index_not_found_exception","reason":"no such index [does-not-exists]"}]},"status":404}
1 Like

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