Reputation: 2149
I'm doing the next query to figure out if a document exist in the db. If exist I am able to return a true, but if the document don't exist in the database already.
I'm getting the next issue:
Unable to execute query due to the following n1ql errors:
{"msg":"No index available on keyspace kids_club that matches your query. Use CREATE INDEX or CREATE PRIMARY INDEX to create an index, or check that your expected index is online.","code":4000}
This is my code, I don't want to get other fields instead the id, because I only want to identify if the document exist:
/**
* Get the ShipRoom document if exists.
* @return Optional-ShipRoom if exist, Optional.empty() otherwise.
*/
@Query("SELECT META(sp).id AS _ID, META(sp).cas AS _CAS"
+ " FROM #{#n1ql.bucket} as sp"
+ " WHERE #{#n1ql.filter}")
Optional<ShipRoom> findShipRoomDocument();
Any advice?
Upvotes: 1
Views: 1339
Reputation: 26151
The error message means you don't have an index that this query can use. Try running that query in the Query Workbench, and you'll get the same error. You'll need to CREATE INDEX
(I have no idea what your WHERE statement looks like so I can't recommend an index).
However, if you have a document ID, you don't need to use a N1QL query to see if it exists or not. There is an Exists() method on the Couchbase Java SDK that you can call instead, and it will work much faster since it doesn't need to incur the overhead of the query/index services.
Upvotes: 1