我在弹性搜索中使用Ingest Attachment Processor Plugin。我需要使用Java API设置附件选项(indexed_chars
,properties
,ignore_missing
等)。我怎么能这样做?
我正在创建索引和设置管道,如下所示:
String id = ...
Map<String, Object> row = ...
client.prepareIndex(indexName, "my_type", id)
.setSource(row)
.setPipeline("my_pipeline")
.execute();
答案 0 :(得分:1)
我找到了答案,如果您有嵌套文档,则必须使用foreach
其他构建json,如documentation
文件:
<强>解决方案:强>
try (XContentBuilder jsonBuilder = XContentFactory.jsonBuilder()) {
BytesReference pipelineSource = jsonBuilder.startObject()
.field("description", "Extract attachment information")
.startArray("processors")
.startObject()
.startObject("foreach")
.field("field", "my_field")
.startObject("processor")
.startObject("attachment")
.field("field", "_ingest._value.my_base64_field")
.field("target_field", "_ingest._value.my_base64_field")
.field("ignore_missing", true)
.field("indexed_chars", -1)
.endObject()
.endObject()
.endObject()
.endObject()
.endArray()
.endObject().bytes();
client.admin().cluster().preparePutPipeline("my_pipeline",
pipelineSource, XContentType.JSON).get();
}
或
你可以手动放在json下面
<强>结果:强>
http://localhost:9200/_ingest/pipeline/my_pipeline
{
"my_pipeline": {
"description": "Extract attachment information",
"processors": [
{
"foreach": {
"field": "my_field",
"processor": {
"attachment": {
"field": "_ingest._value.my_base64_field",
"target_field": "_ingest._value.my_base64_field",
"ignore_missing": true,
"indexed_chars": -1
}
}
}
}
]
}
}