目录
创建索引
PUT /索引的名字
{
"mappings": {
"properties": {
"xxx1属性": {
"type": "该属性的类型"
},
"xxx2属性": {
"type": "该属性的类型"
}
}
}
}
ES客户端:PUT /索引的名字
Linux:curl -X PUT “localhost:9200/commodity?pretty”
Postman:PUT http://127.0.0.1:9200/commodity/_settings
分片数为 3,副本数为 2 的索引
curl -X PUT "localhost:9200/commodity?pretty"
{
"settings": {
"number_of_shards": 3,
"number_of_replicas": 2
},
"mapping": {
"_doc": {
"properties": {
"commodity_id": {
"type": "long"
},
"commodity_name": {
"type": "text"
},
"picture_url": {
"type": "keyword"
}, "price": {
"type": "double"
}
}
}
}
}
修改索引的副本数
PUT http://127.0.0.1:9200/commodity/_settings
{ "number_of_replicas": 3}
为“非查询字段”不建索引
PUT /my_index
{
"mappings": {
"my_type": {
"properties": {
"status_code": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
“index” 控制字段怎样建索引,怎样查询,可用值:
no:此字段不可查询,不建索引
not_analyzed:将字段的原始值放入索引中,作为一个独立的term,它是除string字段以外的所有字段的默认值
analyzed:string字段的默认值,会先进行分析后,再把分析的term结果存入索引中
store就是把这个字段单独存储,默认是不存储的,默认存储的是 _source ,只有设置了才会存储,比如,有一个mapping有三个字段,title,subject,content,其中title,subject比较小,而content非常非常大,如果,你的查询结果只需要title,subject而不需要content时,把title,subject单独存储,可以节省很多时间