这是我目前的模式
{
"mappings": {
"historical_data": {
"properties": {
"continent": {
"type": "string",
"index": "not_analyzed"
},
"country": {
"type": "string",
"index": "not_analyzed"
},
"description": {
"type": "string"
},
"funding": {
"type": "long"
},
"year": {
"type": "integer"
},
"agency": {
"type": "string"
},
"misc": {
"type": "string"
},
"university": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
我上传了70万条记录。在不破坏数据的情况下,如何使大学索引不被“not_analysed”,以使更改反射(reflect)在现有数据中?
最佳答案
现有字段的映射无法修改。
但是,您可以通过两种方式实现所需的结果。
curl -XPUT localhost:9200/YOUR_INDEX/_mapping -d '{ "properties": { "new_university": { "type": "string" } } }'
curl -XPUT localhost:9200/YOUR_INDEX/_mapping -d '{ "properties": { "university": { "type": "string", "index": "not_analyzed", "fields": { "university_analyzed": { "type": "string" // <-- ANALYZED sub field } } } } }'
在这两种情况下,都需要重新索引以便填充新字段。使用_reindex API
curl -XPUT localhost:9200/_reindex -d '{
"source": {
"index": "YOUR_INDEX"
},
"dest": {
"index": "YOUR_INDEX"
},
"script": {
"inline": "ctx._source.university = ctx._source.university"
}
}'
关于elasticsearch - 如何在不破坏Elasticsearch中数据的情况下更改架构?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42711865/