如何使用 QueryBatcher 根据特定列的值获取文档?
How to fetch a document based on a value of the particular column using QueryBatcher?
我想获取状态值为"unprocessed"的所有文档。
我的文件看起来像:
{
"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);
现在,如何获取状态为未处理的文档?
如何修改监听器?
对 status
JSON 属性 使用 AndQuery
to combine the DirectoryQuery
with a ValueQuery
。
final StructuredQueryDefinition query = sqb.and(
sqb.directory(true, "/test/"),
sqb.value(sqb.jsonProperty("status"), "unprocessed")
);
我想获取状态值为"unprocessed"的所有文档。
我的文件看起来像:
{
"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);
现在,如何获取状态为未处理的文档? 如何修改监听器?
对 status
JSON 属性 使用 AndQuery
to combine the DirectoryQuery
with a ValueQuery
。
final StructuredQueryDefinition query = sqb.and(
sqb.directory(true, "/test/"),
sqb.value(sqb.jsonProperty("status"), "unprocessed")
);