Hi,
I’m trying to run a very simple N1QL Query to delete all documents that have keys with a certain prefix.
My CB version is: Version: 4.1.0-5005 Enterprise Edition (build-5005)
My query looks like:
DELETE FROM api
WHERE POSITION(META().id, “cache::”) = 0
I have a primary index built on the api
bucket and a secondary index defined as:
CREATE INDEX id_cache
ON api
(position((meta().id
), “cache::”)) USING GSI
In a test I am running, the api
bucket contains about 100,000 documents and about 70,000 of them have the prefix.
When I run the query from cbq, all of the documents are consistently deleted. However, if I run this as an asynchronous query call from inside a Java program, a variable number of documents are removed each time I run the query.
The rxjava code I am using to perform the query is:
public static Observable executeQueryAsString(AsyncBucket bucket, String queryAsString) {
return bucket.query(N1qlQuery.simple(queryAsString))
.flatMap(result -> result.rows()
.map(row -> new JsonObject(row.value().toString()))
.collect(JsonArray::new, JsonArray::add));
}
It seems as though the query is interrupted before it finishes. I’ve also tried using things like “last()”, “toBlocking()”, and “Observable.zip” with the “finalSuccess” method on the query result observable, but nothing seems to ensure that the query gets finished.
Is there anything obvious that I’m doing wrong? I know that the DELETE statement (and other DML statements) are currently in Beta.
Also, the N1QL takes between 7 and 11 seconds to run. I am running a CB cluster on the same computer that the Java program is running on. That seems slow to me, is there anything that I am missing in terms of using secondary indices properly?
Thanks!
Best,
Perrin