elasticsearch 索引mapping汇总
查看索引字段的映射类型
GET studenttest/_mapping
创建一个新的索引结构
PUT /crawl_sensorexpert_sku_content { "settings": { "number_of_shards" : 3, "number_of_replicas" : 1 }, "mappings": { "properties": { "PN": { "type": "keyword" }, "Title": { "type": "keyword" }, "Brand": { "type": "keyword" }, "Manufacturers": { "type": "keyword" }, "CategoryLevel": { "type": "keyword" }, "CategoryLevel2": { "type": "keyword" }, "CategoryLevel3": { "type": "keyword" }, "ProductUrl": { "type": "keyword" }, "Resources": { "type": "nested", "properties": { "Type": { "type": "short" }, "Url": { "type": "keyword" }, "UrlSSO": { "type": "keyword" }, "Status": { "type": "short" } } }, "Content": { "type": "keyword" }, "ContentNew": { "type": "keyword" }, "HQBuyId": { "type": "long" }, "CreateTime": { "type": "keyword" }, "CreateTimeStamp": { "type": "long" }, "Id": { "type": "keyword" } } } }
添加新字段赋值
//新增字段
put collect_material_pn_address/_mapping
{
"properties": {
"VendorName": {
"type": "keyword"
}
}
}
//赋值
post collect_material_pn_address/_update_by_query
{
"script":{
"lang":"painless",
"source":"if (ctx._source.VendorName == null) {ctx._source.VendorName = 'future'}"
}
}
复制到新索引,可以在程序中或es脚本中创建结构,再执行
//旧索引数据复制到新索引dest中,注意新索引字段结构要与旧索引一致,再执行该语句
POST _reindex
{
"source": {
"index": "collect_material_address"
},
"dest": {
"index": "collect_material_page_address"
}
}
映射字段出现了fields
参考:https://blog.csdn.net/weixin_42982636/article/details/103455525
es的映射常用的二种:一种自动映射,一种属性映射,一般都是用属性映射。参考如下:
通过自动映射 C# 的string类型转成Es字段类型会出现Multi fields,一个test类型一个是keyword类型。test用于分词查询,keyword用于排序和聚合。