我用attachment pipeline插件实现PDF文本的抽取,单个附件上传解析文本内容没有问题,但是多个附件根据pipeline上传时传不上去
原生的命令都可以执行,但是通过Java api上传不了
多附件文本抽取管道和索引都没问题
下面是单个的上传没有问题
/**
* 单个上传文件
*
* @param file
* @throws IOException
*/
public void uploadEs(FileObj file) throws IOException {
IndexRequest indexRequest = new IndexRequest("file");
//上传同时,使用attachment pipline进行提取文件
indexRequest.source(JSON.toJSONString(file), XContentType.JSON);
indexRequest.setPipeline("attachment");
IndexResponse indexResponse = client.index(indexRequest, RequestOptions.DEFAULT);
System.out.println(indexResponse);
}
多个上传时这个方法行不通
try {
BulkRequest bulkRequest = new BulkRequest();
if (dataList != null && dataList.size() > 0) {
for (File obj : dataList) {
bulkRequest.add(
new IndexRequest(index)
.source(JSON.toJSONString(obj), XContentType.JSON).setPipeline("attachment")
);
}
BulkResponse response = client.bulk(bulkRequest, RequestOptions.DEFAULT);
if (!response.hasFailures()) {
return true;
}
}
} catch (Exception e) {
e.printStackTrace();
}
最终目的是想要下面官方文档根据管道批量上传对应的Java代码
PUT my_index/_doc/my_id?pipeline=attachment
{
"attachments" : [
{
"filename" : "ipsum.txt",
"data" : "dGhpcyBpcwpqdXN0IHNvbWUgdGV4dAo="
},
{
"filename" : "test.txt",
"data" : "VGhpcyBpcyBhIHRlc3QK"
}
]
}