本着对知识的考究和敬畏,一切脱离官方文档的解释都是耍流氓,所以,我尽量在官网追本溯源,有本考究。
elasticsearch 是 restful 风格的请求,请求方式有5种:HEAD, GET, POST, PUT, DELETE
索引
index
elasticsearch 官网索引的API,请自行参考阅读。
创建索引,并设置分片和副本数,默认是1个分片,1个副本。索引相当于我们数据库中的表。
PUT /hello-index
{
"settings": {
"index": {
"number_of_shards": 3,
"number_of_replicas": 3
}
}
}
mapping
创建索引同时创建mapping,mapping 相当于表结构的类型定义。和创建表非常的类似,只是elasticsearch 是restful 风格的Json。
PUT /product_info
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 1
},
"mappings": {
"properties": {
"id": {
"type": "long" },
"product_name": {
"type": "text"},
"price": {
"type": "double"},
"product_amount": {
"type": "integer"},
"brand": {
"type": "text"},
"description": {
"type": "text"}
}
}
}
其他索引的请求方式,自行逐一验证,不再截图。
# 查询索引
GET /product_info
# 查询索引的 mapping
GET /product_info/_mapping
# 修改索引名称
PUT /hello-index/_alias/hello_world
# 是否存在索引
HEAD /hello_world
# 修改索引的分片设置
PUT /hello_world/_settings
{
"index" : {
"number_of_replicas" : 2
}
}
# 新增 mapping 属性
PUT /product_info/_mapping
{