IBM / cloudant-java-sdk

Cloudant SDK for Java
Apache License 2.0
22 stars 17 forks source link

Cloudant.deleteIndex( ... ).execute() does not create the correct HTTP request using IndexInformation.getDdoc(). #462

Closed snackerphi closed 1 year ago

snackerphi commented 1 year ago

Describe the bug

To delete an index, the Cloudant::deleteIndex(... .ddoc( ii.getDdoc() ) ...) is sending: DELETE /my_foo-db/_index/_design/_design%2F8a49ddc19c9f8084e81ff8783637b1b30fea460f/json/my_foo-db_name_idx HTTP/1.1 However, according to CouchDB DELETE index, it should be: DELETE /my_foo-db/_index/8a49ddc19c9f8084e81ff8783637b1b30fea460f/json/my_foo-db_name_idx HTTP/1.1

To Reproduce

  1. We query the couchdb database for indexes using the Cloudant java API. List<IndexesInformation> rii cloudant.getIndexesInformation(...)
  2. We loop through the rii to determine if there is an index that needs to be deleted.
  3. We find IndexInformation ii = rii.get( ... ); that needs to be deleted.
  4. We attempt to delete it with: Response<Ok> ro = cloudant.deleteIndex( new DeleteIndexOptions.Builder() .db( dbName ) .index( idxName ) .ddoc( ii.getDdoc() ) .type( ii.getType() ) .build() ).execute();
  5. this fails with the error: com.ibm.cloud.sdk.core.service.exception.NotFoundException: not_found

Using curl:

Expected behavior

HTTP 200 OK

Screenshots

Must gather (please complete the following information):

Additional context

Changing .ddoc( ii.getDdoc() ) to .ddoc( ii.getDdoc().replaceFirst( "^_design/", "" ) ) will work.

Is this the way it is expected to work?

emlaver commented 1 year ago

Hello @snackerphi thanks for reporting this. From our API docs, when getting the list of indexes the response object has this description for ddoc field:

Screenshot 2023-08-29 at 11 12 39 AM

When getting and deleting an index, the description for ddoc states that the string should not contain _design prefix:

Screenshot 2023-08-29 at 11 14 24 AM

It's working as expected but we will update getIndexesInformation response description to make it clear that ddoc includes a _design prefix.

snackerphi commented 1 year ago

OK, thanks!