Elasticsearch和可视化Kibana相关操作创建索引

前言:安装注意点-es与kibana版本要一致

  • 推荐使用docker安装,具体如何使用docker以及docker的容器安装请移步es安装以及配置.,后面我就说安装后es的DSL操作

1.索引(Index)的基本操作

  • 1.1 进入可视化kibana界面后,在Dev tools界面操作DSL语句:
    在这里插入图片描述
  • 1.2 DSL索引操作:
GET /_cat/indices?v 		查看索引信息
PUT /dangdang/       	  	创建索引
DELETE /dangdang			删除索引
DELETE /*					删除所有索引

2.类型(type)的基本操作

  • 索引Mapping Type有:text , keyword , date ,integer, long , double , boolean or ip
  • 1.1 索引不存在时
//创建/dangdang索引并创建(product)类型
PUT /dangdang             
{
  "mappings": {
    "product": {
      "properties": {
        	"title":    { "type": "text"  },
        	"name":     { "type": "text"  },
       		"age":      { "type": "integer" },
        	"created":  {
         		 "type":   "date",
          		 "format": "strict_date_optional_time||epoch_millis"
        		}
      		}
    	}
  	}
}
  • 1.2 索引已经存在时
POST test_index/test_type/_mapping
{
 
   "test_type": {
     "dynamic": false,
     "_all": {
       "enabled": false
     },
     "properties": {
       "wbbh": {
         "type": "keyword"
       },
       "jyxkzbh": {
         "type": "keyword"
       },
       "wbmc": {
         "type": "text",
         "analyzer": "smartcn",
         "fields": {
           "raw": {
             "type": "keyword"
           },
           "standard": {
             "type": "text",
             "analyzer": "standard"
           }
         }
       },
       "zbx": {
         "type": "keyword"
       },
       "zby": {
         "type": "keyword"
       },
       "zby_zbx": {
         "type": "keyword"
       },
       "lksj": {
         "type": "keyword"
       },
       "wbdz": {
         "type": "text",
         "analyzer": "smartcn",
         "fields": {
           "raw": {
             "type": "keyword"
           },
           "standard": {
             "type": "text",
             "analyzer": "standard"
           }
         }
       },
       "cjsj": {
         "type": "date"
       },
       "rksj": {
         "type": "date"
       },
       "gxdwmc": {
         "type": "text",
         "analyzer": "smartcn",
         "fields": {
           "raw": {
             "type": "keyword"
           },
           "standard": {
             "type": "text",
             "analyzer": "standard"
           }
         }
       },
       "wbfzr": {
         "type": "text",
         "analyzer": "smartcn",
         "fields": {
           "raw": {
             "type": "keyword"
           },
           "standard": {
             "type": "text",
             "analyzer": "standard"
           }
         }
       },
       "dt": {
         "type": "keyword"
       },
       "type": {
         "type": "keyword"
       }
     }
   }
}

3.文档(document)的基本操作

3.1添加文档
PUT /ems/emp/1   #/索引/类型/id
{
  "name":"赵小六",
  "age":23,
  "bir":"2012-12-12",
  "content":"这是一个好一点的员工"
}
3.2查询文档
GET /ems/emp/1  
返回结果:
{
  "_index": "ems",
  "_type": "emp",
  "_id": "1",
  "_version": 1,
  "found": true,
  "_source": {
    "name": "赵小六",
    "age": 23,
    "bir": "2012-12-12",
    "content": "这是一个好一点的员工"
  }
}
3.3删除文档
DELETE /ems/emp/1
{
  "_index": "ems",
  "_type": "emp",
  "_id": "1",
  "_version": 2,
  "result": "deleted", #删除成功
  "_shards": {
    "total": 2,
    "successful": 1,
    "failed": 0
  },
  "_seq_no": 1,
  "_primary_term": 1
}
3.4更新文档

ps:PUT也能更新文档,但是会把之前的记录覆盖掉,有的属性也会丢掉,所以使用POST会更好使用

1.第一种方式  更新原有的数据
    POST /dangdang/emp/1/_update
    {
      "doc":{
        "name":"xiaohei"
      }
    }
2.第二种方式  添加新的数据
    POST /ems/emp/1/_update
    {
      "doc":{
        "name":"xiaohei",
        "age":11,
        "dpet":"你好部门"
      }
    }
3.第三种方式 在原来数据基础上更新
	POST /ems/emp/1/_update
    {
      "script": "ctx._source.age += 5"
    }
  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值