查看所有索引

GET _cat/indices

– 创建索引

PUT /demo_test
{
  "settings": {
    "number_of_shards": 2,
    "number_of_replicas": 1
  }
}

– 指定索引 新增字段

PUT /demo_test/_mapping/
{
      "properties":{
      "sku_id":{
        "type":"long"
      },
      "sku_name":{
        "type":"keyword"
      },
      "sku_picture_url":{
        "type":"keyword"
      },
      "address":{
        "type":"text",
		"analyzer": "ik_max_word"
      },
       "createTime" : {
            "type" : "date",
            "format" : "yyyy-MM-dd HH:mm:ss"
      }
    }
  
 }

也可以 同时置顶 settings、mappings

PUT /demo_test/
{
  "settings": {
    "number_of_shards": 2,
    "number_of_replicas": 2
  },
  "mappings": {
    
    "properties":{
      "sku_id":{
        "type":"long"
      },
      "sku_name":{
        "type":"keyword"
      },
      "sku_picture_url":{
        "type":"keyword"
      },
      "address":{
        "type":"text",
		"analyzer": "ik_max_word"
      },
       "createTime" : {
            "type" : "date",
            "format" : "yyyy-MM-dd HH:mm:ss"
      }
    }
    
  } 
  
 }
 
  • 新增数据
 PUT /demo_test/_doc/1
{
	"sku_id": 1,
	"sku_name": "China",
	"address":"中华人民共和国国歌"
}
  • 获取ES 版本信息…
GET /
  • 获取索引信息
GET /demo_test/
  • 查询数据
GET /demo_test/_search
  • 删除索引
DELETE /demo_test
  • 通过 script 给指定字段赋值 (一般新增地段后 给字段赋默认值)
POST /demo_test/_update_by_query
{
  "script": {
    "source": "if (doc['createTime'] == null) {doc['createTime'] = '2022-07-03 00:00:00'}",
    "lang": "painless"
  }
}
Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐