Elasticsearch Java API:[eventDefinitions]的对象映射尝试将字段[null]解析为对象,但找到了具体的价值? [英] Elasticsearch Java API: Object mapping for [eventDefinitions] tried to parse field [null] as object, but found a concrete value?

查看:66
本文介绍了Elasticsearch Java API:[eventDefinitions]的对象映射尝试将字段[null]解析为对象,但找到了具体的价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为以下文档进行映射:

I am trying to make a mapping for the following document work:

{
  "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和其他一些字段,因此我相应地创建了一个映射:

I will exclude the buildInfo and a few other fields, so I created a mapping accordingly:


{
  "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对象的列表,每个json对象将包含 buildInfo eventKey eventDefinition .如您所见, eventDefinition 进一步包含json对象.

This is giving me a MapperParsingException. eventDefinitions is supposed to be a list of json objects each of which will contain buildInfo, eventKey and eventDefinition. eventDefinition further contains json objects as you can see.

@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 中输入每个字段code>当然是分开的,所以我必须给它一个列表,这样它就不会一直映射到最后一个单元,对此我该怎么办?我应该定义名为 EventDefinitionWithBuildInfo的新类型吗? EventDefinition ?

(eventDefinitions is a list of EventDefinitionWithBuildInfo, and each EventDefinitionWithBuildInfo contains buildInfo, eventKey and eventDefinition. EventDefinition further contains a few fields and an object called meta. Although I have mapped all of this out in the mapping, I don't explicitly hand over values for each of the fields to the last branch in the tree. There's no way for me to enter each field in each eventDefinitionWithBuildInfo and then in eventDefinition separately of course, so I have to give it the list, as a result of which it does not get mapped all the way to the last unit. What can I do about this? Should I define new types called EventDefinitionWithBuildInfo and EventDefinition ?

推荐答案

@IanGabes是救世主.我度过了一个周末的哭泣,试图使它正常工作.但是我的对象是如此嵌套,如此分层,并且我期望ES能够自己检测内部字段.我向很多人展示了这一点,他们一无所知.然后,当我无望地看着瑞克和莫蒂(Rick and Morty)掉下来的筹码时,@ IanGabes像天使一样来了,要我简单地使用杰克逊(Jackson)将对象转换为杰森(Json),并且它不会反序列化为最后一个我在做谢谢你.你摇滚,我很烂.

@IanGabes is a savior. I spent my weekend crying and trying to get this working. But my object is so nested, so layered, and I was expecting ES to detect the inner fields on its own. I showed this to so many people and they were clueless. Then, as I was hopelessly watching Rick and Morty with chips falling off of my mouth, @IanGabes came like an angel and asked me to simply use Jackson to convert my object to Json, and that it will not deserialize to the last unit the way I was doing it. Thank you. You rock, I suck.

这篇关于Elasticsearch Java API:[eventDefinitions]的对象映射尝试将字段[null]解析为对象,但找到了具体的价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆