elasticsearch,plugins,Java,elasticsearch,Plugins" /> elasticsearch,plugins,Java,elasticsearch,Plugins" />

Java 如何使用IngestPlugin在Elasticsearch中基于IngestDocument填充indexableField

Java 如何使用IngestPlugin在Elasticsearch中基于IngestDocument填充indexableField,java,elasticsearch,plugins,Java,elasticsearch,Plugins,我正在编写IngestPlugin,它需要根据IngestDocument中的字段填充时间戳(多字段)。我定义了一个索引,如下所示 { "mappings": { "properties": { "field1": { "type": "text", "fields": { "timesta

我正在编写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插件在独立文档上填充多字段(field1.timestamp)值?

您不能直接填充多字段的子字段

由于
field1
的类型为
text
,因此只能设置
“field1”:“2020-07-27”
,您将得到:

  • 字段1中分析
    文本
    值的
    “2020-07-27”
    ,以及
  • 字段1中
    日期
    “2020-07-27”
    。时间戳
因此,您只需执行以下操作:

ingestDocument.setFieldValue("field1", "2020-07-27");
                                    ^
                                    |
                          remove .timestamp here

你能在我的回答中提供一些关于什么对你不起作用的反馈,这样我们就可以解决它了吗?事实上,我想接受一个时间戳值而不是“field1”值。然后你需要为时间戳创建一个单独的字段,而不是子字段。你能解释一下为什么你会这样创建你的映射吗?运气好吗?赏金即将到期,你将白白失去50分。