JSON Processor(JSON 处理器)

原文链接 : https://www.elastic.co/guide/en/elasticsearch/reference/5.3/json-processor.html

译文链接 : http://www.apache.wiki/pages/viewpage.action?pageId=10027814

贡献者 : 那伊抹微笑ApacheCNApache中文网

JSON 字符串转换为一个结构化的 JSON 对象。

Table 23. Json Options(表 23. Json 选项)

Name(名称) Required(必要的) Default(默认值) Description(描述)
field yes - 要解析的 field(字段)
target_field no field 将已转换的结构化对象插入的 field(字段)
add_to_root no false 标记强制将序列化的 json 注入到文档的顶层。在该选项使用时,不得设置 target_field

假设您提供的 json 处理器使用的是如下配置 :

  1. {
  2. "json" : {
  3. "field" : "string_source",
  4. "target_field" : "json_target"
  5. }
  6. }

如果以下文档被处理 :

  1. {
  2. "string_source": "{\"foo\": 2000}"
  3. }

在经过 json 处理器操作之后,结果如下 :

  1. {
  2. "string_source": "{\"foo\": 2000}",
  3. "json_target": {
  4. "foo": 2000
  5. }
  6. }

如果提供以下的配置,省略选项 target_field 设置 :

  1. {
  2. "json" : {
  3. "field" : "source_and_target"
  4. }
  5. }

然后改 json 处理器在这个 document(文档)上操作 :

  1. {
  2. "source_and_target": "{\"foo\": 2000}"
  3. }

结果如下 :

  1. {
  2. "source_and_target": {
  3. "foo": 2000
  4. }
  5. }

这说明,除非在 processor(处理器)配置中明确地命名,否则 target_field 与必要的 **field** 配置中所提供的字段相同。