Zero result with n1ql query with java sdk, where rest api gives results


#1

Hi,
I have three node couchbase cluster

couchbase : 4.1.0.5005
java sdk client : 2.4.2

JsonObject queryParams = JsonObject.create();
Expression expression = x("type").eq("category");
expression.and(x("name").eq("$name"))
queryParams.put("name", "nameVal");
expression.and(x("createdDate").between("$lo_createdDate")).and("$hi_createdDate")
queryParams.put("lo_createdDate", 1492648094000);
queryParams.put("hi_createdDate", 1492730894000);

N1qlParams n1qlParams = N1qlParams.build().adhoc(true);

Statement statment = select(*).from("bucketname").where(expression).limit(100).offset(0)

N1qlQuery query = N1qlQuery.parameterized(statement, queryParams, n1qlParams);

List<T> resultList = new LinkedList<>();
try {
	Bucket.async().query(query)
			.doOnError(err -> {
				throw Exceptions.propagate(err);
			})
			.flatMap(result -> {
                result.errors()
                        .subscribe(errMsgJson -> {
                            log.error(LogConstants.N1QL_ERROR+ errMsgJson);
                        });
                return result.rows();
			})
			.map(row -> {
				try {
					return readRow(row);
				} catch (Exception e) {
					log.error("Failed converting to object in multi get exception {}", e);
					throw Exceptions.propagate(e);
				}
			}).toBlocking().forEach(resultList::add);
}catch (Exception e){
	log.error("Exception:",e);
	throw new DataAccessException(LogConstants.DATABASE_ERROR);
}

Sometimes not able to get any records.
If I do query with REST it gives me result with correct records.

Is there any mistake here?

Thanks in advance
Nihar Rathod


#2

Does it make any difference with adhoc set to false?


#3

Actually, I tried with adhoc(false) and hit bug https://issues.couchbase.com/browse/MB-19659 .
So I put it as true.

Thanks for Quick response. :slight_smile:

Should I use older java sdk client? for compatibility

Nihar Rathod


#4

I suggest you ask that question on the Java SDK forum.


#5

Sorry, It was my mistake. Couchbase is working fine :slight_smile:

Thanks,
Nihar Rathod