Below is the java code:
QueryResult result = bucket.defaultScope().query("select * from _default d where d.name like %$nameParam%",
QueryOptions.queryOptions()
.parameters(JsonObject.create().put("nameParam", param)));
Note: "_default" is my collection and the query works if I remove "like" and parameters options -> (select * from _default)
Below is the error coming :
com.couchbase.client.core.error.ParsingFailureException: Parsing of the input failed
{"completed":true,"coreId":"0x3c3d77b600000001","errors":[{"code":3000,"message":"syntax error - at %!(NOVERB)"}],"httpStatus":400,"idempotent":false,"lastDispatchedFrom":"127.0.0.1:57882","lastDispatchedTo":"127.0.0.1:8093","requestId":11,"requestType":"QueryRequest","retried":0,"service":{"bucket":"CartTest","operationId":"976e0085-c83f-4732-ad8e-7f8e258f52b8","scope":"_default","statement":"select * from _default d where d.name like %$nameParam%","type":"query"},"timeoutMs":75000,"timings":{"dispatchMicros":5828,"totalDispatchMicros":5828,"totalMicros":70213}}
Currently I don't want to use FTS , just want to know the correct syntax for like query ?
You would need to do, "select * from _default d where d.name like '%' || $nameParam || '%'" where "||" is string concat. What goes after "like" should be a string and "$" parameter cannot be inside string literal.