使用com.couchbase.client, java-client
版本2.2.7
,我无法让使用参数化 IN 子句的 n1ql 二级索引正常工作。请参阅下面的示例索引、查询和 java 代码
指数
CREATE INDEX `indexName` ON `bucketName`(id,docType) USING GSI ;
询问
public static final String COUNT_STATEMENT = "select count(*) as count " +
"from bucketName " +
"where docType = 'docId' " +
"and id IN $ids " +
"and publishTimestamp between $startTime and $endTime";
提交查询的代码
public int getCountForDuration(Long startTime, Long endTime, Collection<String> ids){
List<String> idList = new ArrayList<>(ids);
JsonObject placeHolders = JsonObject.create()
.put("ids", JsonArray.from(idList))
.put("startTime", startTime)
.put("endTime", endTime);
N1qlQuery query = N1qlQuery.parameterized(COUNT_STATEMENT, placeHolders)
N1qlQueryResult result = bucket.query(query);
...
}
在添加参数化之前,我的查询正确使用了这个二级索引。如果我使用主索引,我的查询也有效。
我的问题是如何创建将由我的查询使用的二级索引。