我正在尝试为以下文档工作进行映射:
{ "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对象的每一个都将包含的列表buildInfo,eventKey和eventDefinition。eventDefinition如您所见,还包含json对象。
eventDefinitions
buildInfo
eventKey
eventDefinition
@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; }
(eventDefinitions是的清单EventDefinitionWithBuildInfo,每个都EventDefinitionWithBuildInfo包含buildInfo,eventKey和eventDefinition。EventDefinition还包含一些字段和一个名为meta。的对象。尽管我在映射中将所有这些都映射了出来,但是我没有明确地将每个字段的值移交给最后一个当然,我没有办法分别输入每个字段eventDefinitionWithBuildInfo,然后再eventDefinition分别输入,因此我必须给它一个列表,其结果是它不会一直映射到最后一个单元。我该怎么办?我应该定义称为EventDefinitionWithBuildInfo and的 新类型EventDefinition吗?
EventDefinitionWithBuildInfo
EventDefinition
meta
eventDefinitionWithBuildInfo
@IanGabes是救世主。我度过了一个周末的哭泣,试图使它正常工作。但是我的对象是如此嵌套,如此分层,并且我期望ES能够自己检测内部字段。我向很多人展示了这一点,他们一无所知。然后,当我无望地看着瑞克和莫蒂(Rick and Morty)掉下来的筹码时,@ IanGabes像天使一样来到,要求我简单地使用杰克逊(Jackson)将对象转换为杰森(Json),并且它不会反序列化为最后一个单元我在做 谢谢。你摇滚,我很烂。