Update Mapping
3778 ワード
field mappings cannot be changed
--> except for some parameters like ignore_above, etc.
mapping is immutable as data could already been indexed
changing type requires whole data structure to be rebuild
docs need to be reindexed for type change
1. Reindex API
data type doesn't reflect how the values are indexed it is used to represent _source data data types can also be handled at the application level
scripts can be supplied on reindex script above changes product_id _source data from int to string
removing fields field mappings cannot be deleted omitting fields when indexing docs is possible to reclaim disk space used by a field, use source filtering
specify array of field names to be reindexed
For the size of docs, reindexing may be inefficient field aliases doesn't required reindex
ex) adding alias comment for field content only the target field of field aliases can be updated similar to field alias, index can also have alias
--> except for some parameters like ignore_above, etc.
mapping is immutable as data could already been indexed
changing type requires whole data structure to be rebuild
docs need to be reindexed for type change
1. Reindex API
retrieves docs from source index and indexes it to the destination index
1-1. reindexing
PUT /reviews_new
{
"mappings" : {
"properties" : {
"author" : {
"properties" : {
"email" : {
"type" : "keyword",
"ignore_above" : 256
},
"first_name" : {
"type" : "text"
},
"last_name" : {
"type" : "text"
}
}
},
"content" : {
"type" : "text"
},
"created_at" : {
"type" : "date"
},
"product_id" : {
"type" : "keyword" // changed from "integer"
},
"rating" : {
"type" : "float"
}
}
}
}
POST /_reindex
{
"source" : {
"index" : "reviews"
},
"dest" : {
"index" : reviews_new
}
}
PUT /reviews_new
{
"mappings" : {
"properties" : {
"author" : {
"properties" : {
"email" : {
"type" : "keyword",
"ignore_above" : 256
},
"first_name" : {
"type" : "text"
},
"last_name" : {
"type" : "text"
}
}
},
"content" : {
"type" : "text"
},
"created_at" : {
"type" : "date"
},
"product_id" : {
"type" : "keyword" // changed from "integer"
},
"rating" : {
"type" : "float"
}
}
}
}
POST /_reindex
{
"source" : {
"index" : "reviews"
},
"dest" : {
"index" : reviews_new
}
}
1-2. reindexing & updating _source
scripts can be supplied on reindex
POST /_reindex
{
"source" : {
"index" : "reviews"
},
"dest" : {
"index" : reviews_new
},
"script" : {
"source" : """
if (ctx._source.product_id != null) {
ctx._source.product_id = ctx._source.product_id.toString();
}
"""
}
}
1-3. reindex with condition
1-4. reindex only selected fields
1-5. change field name
2. Field Alias
ex) adding alias comment for field content
PUT /reviews/_mapping
{
"properties" : {
"comment" : {
"type" : "alias",
"path" : "content"
}
}
}
Reference
この問題について(Update Mapping), 我々は、より多くの情報をここで見つけました https://velog.io/@sangmin7648/Update-Mappingテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol