文章目录
1.索引的基本操作
1.1新建 Index
1.2删除 Index
1.3新增记录
1.4查看记录
1.5删除记录
1.6更新记录
2.数据查询
2.1返回所有记录
2.2全文搜索
1. 索引的基本操作
1.1 新建 Index
可以直接向 Elastic 服务器发出 PUT 请求
新建一个名叫 weather 的 Index
$ curl -X PUT 'localhost:9200/weather'
复制代码
服务器返回一个 JSON 对象,里面的 acknowledged 字段表示操作成功。
{ "acknowledged":true, "shards_acknowledged":true }
1.2 删除 Index
发 DELETE 请求删除即可
$ curl -X DELETE 'localhost:9200/weather'
复制代码
1.3 新增记录
PUT请求 指定 id 新增记录,id 为字符串即可。
$ curl -X PUT 'localhost:9200/accounts/1' -d ' { "user": "张三", "title": "工程师", "desc": "数据库管理" }'
复制代码
POST请求则会自动生成随机字符串 id
1.4 查看记录
向/Index/Type/Id发出 GET 请求,参数 pretty=true 表示以易读的格式返回
$ curl 'localhost:9200/accounts/1?pretty=true'
复制代码