1.创建索引并定义映射
PUT cars
{
"mappings": {
"properties": {
"brand": {
"type": "text"
},
"model": {
"type": "text"
},
"mileage": {
"type": "long"
}
}
}
}
2.更新索引映射
PUT cars/_mapping
{
"properties": {
"length": {
"type": "float" // 或者使用 "type": "integer" 如果长度是整数
}
}
}
3.更新文档
POST cars/_update_by_query
{
"script": {
"source": "ctx._source.length = 4.8",
"lang": "painless"
},
"query": {
"term": {
"brand.keyword": "Toyota"
}
}
}
4.更新单个文档
POST cars/_update/1
{
"doc": {
"length": 4.8
}
}