ES-基础命令总结

1. 创建索引

POST http://localhost:9200/movies

创建成功提示:

{
   "acknowledged": true
}

2. 查看索引的状态

//浏览器中执行
http://ds0:9200/_cat/indices?v

3. 添加索引信息(更新索引信息=》相同的索引,相同的类型,相同的ID)

PUT http://ds0:9200/movies/movie/1
{
    "title": "The Godfather",
    "director": "Francis Ford Coppola",
    "year": 1972
}

创建成功提示:

{
   "_index": "movies",
   "_type": "movie",
   "_id": "1",
   //版本号(_version)可用于跟踪文档已编入索引的次数。
   "_version": 1,
   "result": "created",
   "_shards": {
      "total": 2,
      "successful": 1,
      "failed": 0
   },
   "created": true
}

3. 获取文档或者索引

GET http://ip:port/索引/类型/ID

获取成功提示:

{
   //索引名
   "_index": "movies",
   //类型
   "_type": "movie",
   //ID
   "_id": "1",
   //已经被更新的次数
   "_version": 4,
   "found": true,
   //索引原内容
   "_source": {
      "title": "The GodFather",
      "director": "Francis Ford Coppola",
      "year": 1972,
      "genres": [
         "Crime",
         "Drama"
      ]
   }
}

更新文档内容

http://ds0:9200/secisland/secilog/1/_update/
{
"doc":{
"computer":"secisland",
"message":"secisland is an security computer.It provides log analysis products"
}
}

更新成功结果:

{
"_index": "secisland",
"_type": "secilog",
"_id": "1",
"_version": 2,
"_shards": {
"total": 2,
"successful": 2,
"failed": 0
}
}

4. 删除文档或者索引

DELETE  http://ip:port/索引名/类型名/ID

删除成功后:

{
   //表示文档已经找到并且操作成功
   "found": true,
   "_index": "movies",
   "_type": "movie",
   "_id": "1",
   "_version": 5,
   "_shards": {
      "total": 2,
      "successful": 2,
      "failed": 0
   }
}
5. _search端点用于搜索
<index>/<type>/_search
//其中index和type都是可以去掉的
6. 在URL后面添加?pretty的意义
  • 在任意的查询字符串中增加pretty参数,会让Elasticsearch美化输出(pretty-print)JSON响应以便更加容易阅读。不包含(_source,这个字段由用户输入时的格式一致)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

NobiGo

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值