java - 如何使用 IngestPlugin 在 Elasticsearch 中基于 IngestDocument 填充 indexableField
问题描述
我正在编写 IngestPlugin,它需要根据 IngestDocument 中的字段填充时间戳(多字段)。我已经定义了一个索引如下
{
"mappings": {
"properties": {
"field1": {
"type": "text",
"fields": {
"timestamp": {
"type": "date",
"format": "yyyy-MM-dd"
}
}
},
"field2": {
"type": "text",
"fields": {
"timestamp": {
"type": "date",
"format": "yyyy-MM-dd"
}
}
},
"field3": {
"type": "text"
}
}
},
"settings": {
"default_pipeline": "my_pipeline"
}
}
我尝试使用这样的处理器为“title.timestamp”设置值
@Override
public IngestDocument execute(IngestDocument ingestDocument) throws Exception {
ingestDocument.setFieldValue("field1.timestamp", "2020-07-27");
return ingestDocument;
}
插入文档时出现以下错误
{
"error" : {
"root_cause" : [
{
"type" : "illegal_argument_exception",
"reason" : "cannot set [timestamp] with parent object of type [java.lang.String] as part of path [field1.timestamp]"
}
],
"type" : "illegal_argument_exception",
"reason" : "cannot set [timestamp] with parent object of type [java.lang.String] as part of path [field1.timestamp]"
},
"status" : 400
}
有没有办法使用 Elasticsearch 插件在 indesting 文档上填充多字段(field1.timestamp)值?
解决方案
您不能直接填充多字段的子字段。
由于field1
是 type text
,你只能设置"field1": "2020-07-27"
,你会得到:
- in的分析
text
值和"2020-07-27"
field1
- 的
date
值"2020-07-27"
_field1.timestamp
所以你需要简单地这样做:
ingestDocument.setFieldValue("field1", "2020-07-27");
^
|
remove .timestamp here
推荐阅读
- c - 为什么我的 C 程序不等待扫描输入?
- angular - 如何以角度正确地从拦截器调用服务方法
- docker - 为什么 docker-compose 卷没有正确安装?(我在 docker 中使用 nginx 和 certbot)
- kubernetes - Nginx 控制器的基于路径的路由不起作用
- uml - 如何建模一个简单的锻炼应用程序(类图)
- amazon-web-services - AWS Eventbridge 规则能否匹配数组内的对象
- windows - 如何找出用户机器上安装了哪些 Visual Studio 扩展?
- sql - 在使用 Tableau 时保存 SQL 版本的最佳方法是什么?
- javascript - If 语句始终返回 True
- bash - 获取准备好进行阶段批准的 AWS 管道列表