java - Creating Couchbase views in code: First query returns 0 rows, index builds in background -


i creating view in code using couchbase java api 2.1.2 this:

defaultview view = defaultview.create(viewname, jsmapfunctionasstring); list<view> views = new arraylist<>(); views.add(view); designdocument doc = designdocument.create(name, views); bucket.bucketmanager().insertdesigndocument(doc); 

calling viewresult result = bucket.query(viewquery.from(name, viewname)) directly after inserting document, viewresult.success() returns true, both iterators rows() , iterator return 0 rows (there results present. when execute view in web interface, returns correct values).

the workaround found after several hours call query twice enough waiting time in between like

viewresult result = bucket.query(viewquery.from(name, viewname)); thread.sleep(10000); result = bucket.query(viewquery.from(name, viewname)); 

the second call return correct result.

it seems if couchbase has build index query first returns directly, before index has been built.
waiting 10 seconds of course not optimal, maybe creating index take more time in future.

so question is, how can make sure, wait until index has been built?
bug in api?

you can use stale method , set false in viewquery, force wait indexation finish before returning results.


Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -