user7494712
user7494712

Reputation:

Insert data in a partition of CouchDB from java

I'm using cloudant API for CouchDB in JAVA. I've created a partitioned database from Java but now i don't know how to create a partition and insert my json in this one.

final String dbName = "cinema";
        CloudantClient client = ClientBuilder.url(new URL(url)).username(username).password(passw).build();
        System.out.println("Server version: " + client.serverVersion());
        Database db = CreatePartitioned.createPartitionedIfNotExists(client, dbName);
        db.createIndex("movies"); //doesn't work

I have this error:

Exception in thread "main" com.cloudant.client.org.lightcouch.CouchDbException: 400 Bad Request at http://127.0.0.1:5984/movielens/_index. Error: bad_request. Reason: invalid UTF-8 JSON.
    at com.cloudant.client.org.lightcouch.CouchDbClient.execute(CouchDbClient.java:597)
    at com.cloudant.client.org.lightcouch.CouchDbClient.executeToInputStream(CouchDbClient.java:648)
    at com.cloudant.client.api.Database.createIndex(Database.java:391)
    at provaCouch.Prova_CouchDB.main(Prova_CouchDB.java:20)

I have to create 3 partition and on the net there are poor information. Does anybody know how to fix this problem?

Upvotes: 1

Views: 624

Answers (1)

xpqz
xpqz

Reputation: 3737

It looks like you're not sending the correct argument to createIndex().

See the docstring for the createIndex method, and the API doc it references. You will probably want to use the index builder instead (com.cloudant.client.api.query.JsonIndex.Builder).

Upvotes: 1

Related Questions