我继承了一个遗留代码,该代码使用Elastic Search API创建索引和索引内容。
映射JSON是为v1.5创建的,其外观如下:
{
"settings": {
"index": {
"number_of_shards": 1,
"number_of_replicas": 0
},
"mappings": {
"users": {
"properties": {
"created_at": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss"
},
"id": {
"type": "double"
},
"name": {
"type": "string"
},
"org_id": {
"type": "double"
},
"type_priority": {
"type": "double"
}
}
},
"comment_idea": {
"properties": {
"author_id": {
"type": "double"
},
"comment": {
"type": "string"
},
"created_at": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss"
},
"id": {
"type": "double"
},
"idea_id": {
"type": "double"
},
"org_id": {
"type": "double"
}
}
},
}
}
当然,还有更多类型,例如 users , comment_idea ,如上例所示。
由于我对Elastic Search不太熟悉,我的问题是如何为7.1转换此映射JSON?
据我所知7.1删除了 types ,并且此映射JSON被认为是无效的-我没有收到错误,但不接受(创建)该映射。
答案 0 :(得分:1)
由于您不能在一个索引中存储多个映射类型,因此您需要将该多类型索引拆分为多个索引。另外,您需要将string
更改为text
。
因此,您需要创建多个索引,如下所示:
PUT users
{
"settings": {
"index": {
"number_of_shards": 1,
"number_of_replicas": 0
}
},
"mappings": {
"properties": {
"created_at": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss"
},
"id": {
"type": "double"
},
"name": {
"type": "text"
},
"org_id": {
"type": "double"
},
"type_priority": {
"type": "double"
}
}
}
}
PUT comment_idea
{
"settings": {
"index": {
"number_of_shards": 1,
"number_of_replicas": 0
}
},
"mappings": {
"properties": {
"author_id": {
"type": "double"
},
"comment": {
"type": "text"
},
"created_at": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss"
},
"id": {
"type": "double"
},
"idea_id": {
"type": "double"
},
"org_id": {
"type": "double"
}
}
}
}