ElasticSearch(一):入门

一 Index

  • 索引
    索引中存储相同结构的文档,每个索引有自己的mapping定义,用于定义字段名和类型;
  • 操作
#创建索引
PUT /test_index
#获取所有索引
GET _cat/indices
#删除索引
DELETE test_index

二 Document

  • 文档
    由字段JsonObject组成,每个文档有唯一的id标识,可以自行指定,也可以自动生成;
    每个文档有元数据,用于标注文档的相关信息,_index/-type/_id/_uid/_source等;
  • 操作
#创建文档指定id
PUT /test_index/doc/1
{
  "username":"alfred",
  "age":1
}
#创建文档不指定id
POST /test_index/doc
{
  "username":"tom",
  "age":20
}
#查询文档指定id
GET /test_index/doc/1
#查询所有文档
GET /test_index/doc/_search
#批量添加文档 
#index/create/delete/update index创建时可以替换文档,create创建时不可以替换
POST _bulk
{"index":{"_index":"test_index","_type":"doc","_id":"3"}}
{"username":"alfred","age":20}
{"delete":{"_index":"test_index","_type":"doc","_id":"1"}}
{"update":{"_id":"2","_index":"test_index","_type":"doc"}}
{"doc":{"age":"20"}}
#批量查询文档
GET /_mget
{
  "docs": [
    {"_index": "test_index","_type": "doc","_id": "3"},
    {"_index": "test_index","_type": "doc","_id": "2"}
  ]
}

你可能感兴趣的:(ElasticSearch(一):入门)