json 包含字符串和对象的数组在 Elasticsearch 中的集合映射中
json array with string and objects inside set mapping in Elasticsearch
这里有两个 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
字段映射?
我尝试了 string
和 object
类型,但都失败了。
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
}
所有字段必须是同一类型。您不能将字符串与对象混合
"Univ Philippines", --> text
{ --> object
"pref": "Y",
"content": "University of the Philippines System"
}"
您需要将 "Univ Philippines" 定义为 "University":"Univ Philippines"(添加一些键 "university" 等)。
这里有两个 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
字段映射?
我尝试了 string
和 object
类型,但都失败了。
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
}
所有字段必须是同一类型。您不能将字符串与对象混合
"Univ Philippines", --> text
{ --> object
"pref": "Y",
"content": "University of the Philippines System"
}"
您需要将 "Univ Philippines" 定义为 "University":"Univ Philippines"(添加一些键 "university" 等)。