Elasticsearch Java API:[eventDefinitions] 的对象映射试图将字段 [null] 解析为对象,但找到了具体值?

Elasticsearch Java API: Object mapping for [eventDefinitions] tried to parse field [null] as object, but found a concrete value?

我正在尝试为以下文档制作映射:

{
  "eventDatabase": "abc",
  "usageLibraryEventType": "ABC",
  "name": "Prionti",
  "namespace": "Prionti's namespace",
  "latestBuildTimestamp": 1581348323634,
  "flattenedEventProperties": [
    "User Id"
  ],
  "eventDefinitions": [
    {
      "buildInfo": {
        "baseVersion": "1",
        "branch": "master",
        "buildName": "something.com",
        "orgName": "Prionti's org",
        "repoName": "myrepo",
        "buildTimestamp": 1581348323634,
        "packageName": "myrepo",
        "packagePath": "",
        "resolvedVersion": "1.2920",
        "rootModuleName": "repo",
        "rootPackagePath": ""
      },
      "eventKey": "myEvent",
      "eventDefinition": {
        "name": "myName",
        "namespace": "myNamespace",
        "meta": {
          "description": "No description available",
          "database": "myDatabase",
          "owner": null,
          "codeOwners": [
            "Prionti Nasir"
          ],
          "imgSrc": null,
          "isPublic": null,
          "yamlSrc": {
            "packageName": "my-package",
            "packageVersion": "static-1.2920",
            "relativePath": "something.yaml"
          }
        },
        "properties": {
          "userId": {
            "type": "number",
            "options": null,
            "isOptional": false,
            "description": null
          }
        },
        "class": "interaction"
      }
    }
  ]
}

我将排除 buildInfo 和其他一些字段,因此我相应地创建了一个映射:


{
  "settings": {
    "index": {
      "number_of_replicas": "2",
      "number_of_shards": "25",
      "analysis": {
        "analyzer": {
          "autocomplete": {
            "filter": [
              "lowercase",
              "autocomplete_filter"
            ],
            "tokenizer": "standard",
            "type": "custom"
          },
          "prefixMatch": {
            "filter": [
              "lowercase"
            ],
            "tokenizer": "standard",
            "type": "custom"
          }
        },
        "filter": {
          "autocomplete_filter": {
            "min_gram": "3",
            "max_gram": "10",
            "type": "edge_ngram"
          }
        }
      }
    }
  },
  "mappings": {
    "usageLibraryEventType": {
      "dynamic": false,
      "properties": {
        "eventDatabase": {
          "properties": {
            "name": {
              "type": "string"
            }
          },
          "enabled": "false"
        },
        "eventType": {
          "type": "string",
          "analyzer": "autocomplete"
        },
        "name": {
          "type": "string",
          "analyzer": "autocomplete"
        },
        "namespace": {
          "type": "string",
          "analyzer": "autocomplete"
        },
        "latestBuildTimestamp": {
          "type": "long"
        },
        "flattenedEventProperties": {
          "type": "string"
        },
        "eventDefinitions": {
          "properties": {
            "eventKey": {
              "type": "string",
              "index": "not_analyzed"
            },
            "eventDefinition": {
              "properties": {
                "name": {
                  "type": "string",
                  "index": "no"
                },
                "namespace": {
                  "type": "string",
                  "index": "no"
                },
                "meta": {
                  "properties": {
                    "description": {
                      "type": "string",
                      "analyzer": "prefixMatch"
                    },
                    "owner": {
                      "type": "string",
                      "index": "not_analyzed",
                      "null_value" : "N/A"
                    },
                    "codeOwners": {
                      "type": "string",
                      "index": "not_analyzed",
                      "null_value" : "N/A"
                    }
                  }
                },
                "class": {
                  "type": "string",
                  "index": "not_analyzed"
                }
              }
            }
          }
        }
      }
    }
  }
}

这是给我一个 MapperParsingException。 eventDefinitions 应该是 json 个对象的列表,每个对象将包含 buildInfoeventKeyeventDefinition。如您所见,eventDefinition 还包含 json 个对象。

@POST
  public UsageLibraryEventType indexEventType(UsageLibraryEventType usageLibraryEventType) {
    elasticsearchIndexerClient.addDocumentRequest(
        new IndexRequest(config.getUsageLibrarySourceTopic(), TYPE)
            .source(
                "eventDatabase", usageLibraryEventType.getEventDatabase(),
                "eventType", usageLibraryEventType.getUsageLibraryEventType(),
                "name", usageLibraryEventType.getName(),
                "namespace", usageLibraryEventType.getNamespace(),
                // fix these field names
                "latestBuildTimestamp", usageLibraryEventType.getLatestBuildTimestamp(),
                "flattenedEventProperties", usageLibraryEventType.getFlattenedEventProperties(),
                "eventDefinitions", usageLibraryEventType.getEventDefinitions()),
        config.getUsageLibrarySourceTopic())
        .join();
    return usageLibraryEventType;
  }

(eventDefinitionsEventDefinitionWithBuildInfo的列表,每个EventDefinitionWithBuildInfo包含buildInfoeventKeyeventDefinitionEventDefinition 进一步包含一些字段和一个名为 meta 的对象。虽然我已经在映射中映射了所有这些,但我没有明确地将每个字段的值移交给树中的最后一个分支。当然,我无法在每个 eventDefinitionWithBuildInfo 中输入每个字段,然后在 eventDefinition 中分别输入,所以我必须给它列表,因此它不会一直映射到最后一个单元。我该怎么办?我应该定义名为 EventDefinitionWithBuildInfoEventDefinition 的新类型吗?

@IanGabes 是救世主。我整个周末都在哭泣,并试图让它发挥作用。但是我的对象是如此嵌套,如此分层,我希望 ES 能够自行检测内部字段。我把这个展示给很多人看,他们都一无所知。然后,当我绝望地看着瑞克和莫蒂的筹码从我嘴里掉下来时,@IanGabes 像天使一样来了,让我简单地使用 Jackson 将我的对象转换为 Json,并且它不会反序列化为最后一个单元就像我做的那样。谢谢你。你摇滚,我烂