Query Example fetching multiple documents matching a attribute value

I have a java application and want to store some pojos in Couchbase and retrieve all the pojos of a certain class by one of the fields in the pojo.

The java class is something like this:

public class RuleDefinition implements Serializable{

private static final long serialVersionUID = 1L;
private Long id;
private String ruleName;
private String ruleDescription;
private String criteriaClauses;
private String scriptBody;
private String javaClassPath;
private String eventKey;

//with all the standard getter’s and setters, constructors, etc.

I have persisted in the RDBMS via Hibernate in the past and want to use Couchbase.

I am looking for a Couchbase example to mimic the database SQL

SELECT * FROM RuleDefinition where eventKey like ‘myperfectrules’

I can store the individual RuleDefinition pojos in couchbase and retrieve them by the “id” string.


First of all if you want to query the value inside Couchbase, you need to create an index as document here:

The views, are executed on each value store in the document allowing you to create an index. The easiest way is to use JSON document, so I am inviting your to use a JSON serializer when saving your Java object in Couchbase, then you can create an index for example

function (doc,meta) { if (doc.eventKey) { emit(doc.eventKey); } }

Then you can query this index in your application for example: ?key=“myperfectrules”

I invite you to look at the following article:


Yes got it thanks.