【问题标题】:json array with string and objects inside set mapping in Elasticsearch在 Elasticsearch 中的集合映射中包含字符串和对象的 json 数组
【发布时间】:2020-08-03 16:58:48
【问题描述】:

这里有两个json:

json 1:

{
  "organization": [
    "Univ Philippines",
    {
      "pref": "Y",
      "content": "University of the Philippines System"
    },
    {
      "pref": "Y",
      "content": "University of the Philippines Diliman"
    }
  ]
}

json 2:

{
   "organization": "Univ Philippines"
}

我需要将它们索引到 Elasticsearch 中。如何设置organization字段映射?

我试过stringobject类型,但都失败了。

PUT sci_test
{
  "mappings": {
    "sci":{
      "properties": {
        "organization":{
          "type": "object"
        }
      }
    }
  }
}
PUT sci_test/sci/1
{
  "organization": [
    "Univ Philippines",
    {
      "pref": "Y",
      "content": "University of the Philippines System"
    },
    {
      "pref": "Y",
      "content": "University of the Philippines Diliman"
    }
  ]
}

error info:
{
  "error": {
    "root_cause": [
      {
        "type": "mapper_parsing_exception",
        "reason": "object mapping for [organization] tried to parse field [null] as object, but found a concrete value"
      }
    ],
    "type": "mapper_parsing_exception",
    "reason": "object mapping for [organization] tried to parse field [null] as object, but found a concrete value"
  },
  "status": 400
}

【问题讨论】:

    标签: elasticsearch mapping elasticsearch-5 elk


    【解决方案1】:

    所有字段必须属于同一类型。您不能将字符串与对象混合

    "Univ Philippines",                                      --> text
     {                                                       --> object
          "pref": "Y",
          "content": "University of the Philippines System"
     }"
    

    您需要将“Univ Philippines”定义为“University”:“Univ Philippines”(添加一些关键的“大学”等)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-31
      • 2018-05-29
      • 2017-09-17
      • 1970-01-01
      • 2019-06-06
      相关资源
      最近更新 更多