我想获取状态值为“未处理”的所有文档。
我的文档如下:
{
"EMPID": "102",
"Fname": "FName2",
"Lname": "LastName2",
"DOB": "02012001",
"age": "19",
"Gender": "F",
"Pay": "21",
"status": "unprocessed"
}
这些文档的URI类似于“ / test / 102 / FName2 /”
我可以使用以下代码从数据库中获取所有文档:
QueryManager queryManager=client.newQueryManager();
StructuredQueryBuilder sqb = queryManager.newStructuredQueryBuilder();
StructuredQueryDefinition query = sqb.directory(true, "/test/");
DataMovementManager dmm = client.newDataMovementManager();
QueryBatcher batcher = dmm.newQueryBatcher(query);
batcher.onUrisReady(
new ExportListener()
.onDocumentReady(doc-> {
String uriParts[] = doc.getUri().split("/");
try {
Files.write(
Paths.get(DATA_DIR, "output",
uriParts[uriParts.length - 1]),
doc.getContent(new StringHandle()).toBuffer());
} catch (Exception e) {
e.printStackTrace();
}
}))
.onQueryFailure( exception -> exception.printStackTrace() );
dmm.startJob(batcher);
现在,我该如何获取状态为未处理的文档? 如何修改监听器?
答案 0 :(得分:3)
使用AndQuery
将DirectoryQuery
与ValueQuery
合并为status
JSON属性。
final StructuredQueryDefinition query = sqb.and(
sqb.directory(true, "/test/"),
sqb.value(sqb.jsonProperty("status"), "unprocessed")
);