JAVA SDK vs REST API different results

Hello !

I have problem with CouchBase 4.0.0-4051 Enterprise Edition.

Query in Java :

ViewResult result = bucket.query(ViewQuery.from("test", "me").stale(Stale.TRUE).inclusiveEnd(true).key(key));

Query in Rest :

http://localhost:8092/bucket/_design/test/_view/me?inclusive_end=true&stale=ok&key=key

Rest output is good result but Java output every time is different something like 10 rows,214 rows,214 rows,15 rows etc…

What is problem?

Thanks for help!

Hi @firas,

can you run toString() on the ViewQuery before passing it in to the query() method and comparing it to the request you perform directly over http? See if there are any differences?

Hello @daschl :smile:

OUTPUT :

"stale=ok&inclusive_end=true&key=key"

@firas are you writing documents at the same time? So the view will be updated while you are querying it?

@daschl
I ask about the same VIEW in same time. REST giving me good results but JAVA SDK give me 13 rows , 25 rows, 150 rows… etc .

My view is updating all the time because it’s huge data…

@firas if your data is updating all the time, it is kind of expected that java is returning different results all the time?

One thing that is not clear to me is the exact issue you are having. Let me rephrase that: while data is being mutated, you are issuing N queries over http direct in 1 second intervals and they don’t change, while when you issue N sdk queries in 1 second intervals and they do change?

That would be surprising to me, since as you probably know, the SDK also just executed http calls in the background, so it would come down to the same queries. Can you share more information about the exact test case and scenario you are performing?

@daschl

I just updating all the time the same ID’s by maybe another values or the same and expiry time (2 hours).
Data size ( ~1 milion documents) ID looks like this blabla,blabla2,blabla3 .
I emit 2 informations emit([blabla1,blabla2],doc) emit([blabla1,blabla2,blabla3],doc).
When I updating all time time this documents my view is updating so I ask about stale “TRUE/OK” because I want fast response.

I ask about some “key” by REST I geting full response (that what I expect) but when I ask in SDK result is different, sometimes had 10 documents or 150 documents. I never get expected result.

I think problem is I updating that documents all the time but why REST response is other?

Query Code :

        CouchbaseEnvironment env = DefaultCouchbaseEnvironment.builder()
    		.queryTimeout(Long.MAX_VALUE)
    		.kvTimeout(Long.MAX_VALUE)
    		.maxRequestLifetime(Long.MAX_VALUE)
    		.managementTimeout(Long.MAX_VALUE)
    		.viewTimeout(Long.MAX_VALUE)
    		.connectTimeout(Long.MAX_VALUE)
    		.keepAliveInterval(Long.MAX_VALUE)
    		.build();
	
	CouchbaseCluster cluster = CouchbaseCluster.create(env,"127.0.0.1");
	
	JsonArray startKey = JsonArray.create();
	startKey.add("KEY");
	startKey.add("KEY2");

	Bucket bucket = cluster.openBucket("example");
	
	ViewResult result = bucket.query(ViewQuery.from("me", "query").stale(Stale.TRUE).inclusiveEnd(true).key(startKey));

	bucket.close();
	
	for (ViewRow row : result.allRows()) {
             ...............
	}

When I create default env result is the same…

Okay, so first your custom environment doesn’t make much sense, just use the default one.
Next, do not close the bucket until you finished all your stuff

Finally, the code as it stands here will trigger a key=["KEY, “KEY2”] I don’t think thats what you want unless the key you emit in a view is like emit(["KEY, “KEY2”,null); and NOT two separate emits.

Are you sure that you actually don’t want “keys” instead of key? if you use keys, then rows with either “KEY” or “KEY2” will be returned.