ES 7 中在创建索引时指定 Mapping
PUT school
{
"mappings" : {
"properties" : {
"name" : {
"type" : "keyword"
}
}
}
}
响应:
{
"acknowledged" : true,
"shards_acknowledged" : true,
"index" : "school"
}
然后可以通过GET school
查询索引信息。
ES 7 中先建索引,再自定义 mapping
PUT school
PUT school/_mapping
{
"properties" : {
"name" : {
"type" : "keyword"
}
}
}
ES 7 建索引时指定mapping和settings
比如创建索引时指定分片数和副本数:
PUT school
{
"mappings" : {
"properties" : {
"name" : {
"type" : "keyword"
}
}
},
"settings" : {
"index" : {
"number_of_shards" : 1,
"number_of_replicas" : 2
}
}
}
ES 6 中在创建索引时指定 Mapping 和 Setting
因为 ES 7 之前的版本,一个index下支持多个type,所以mappings
下一层要指定 type
。
PUT school
{
"mappings" : {
"student": {
"properties" : {
"name" : {
"type" : "keyword"
}
}
}
},
"settings" : {
"index" : {
"number_of_shards" : 1,
"number_of_replicas" : 2
}
}
}