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,这个字段由用户输入时的格式一致)

猜你喜欢

转载自blog.csdn.net/it_dx/article/details/81586264