elasticsearch简单操作(一)
生活随笔
收集整理的這篇文章主要介紹了
elasticsearch简单操作(一)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1、增加記錄
例如1:向指定的 /Index/Type 發送 PUT 請求,就可以在 Index 里面新增一條記錄。比如,向/accounts/person發送請求,就可以新增一條人員記錄。
curl -X POST 'localhost:9200/accounts/person/2' -d '{"user":"張三","title": "工程師","desc":"系統管理"}'系統提示如下錯誤:
{"error":"Content-Type header [application/x-www-form-urlencoded] is not supported","status":406}
需要制定插入數據格式:如下
curl -H "Content-Type: application/json" -X POST 'localhost:9200/accounts/person/2' -d '{"user":"張三","title": "工程師","desc":"系統管理"}'系統提示:
{"_index":"accounts","_type":"person","_id":"2","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":0,"_primary_term":1}說明插入成功
?
例如2:
curl -H "Content-Type: application/json" -X PUT 'localhost:9200/accounts/person/4' -d '{"user":"李四","title": "軟件工程師","desc":"系理集成"}'系統提示:
{"_index":"accounts","_type":"person","_id":"4","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":1,"_primary_term":1}說明插入成功。
?
可以使用PUT、POST插入數據,需要制定插入數據的數據格式,用?-H "Content-Type: application/json"制定為json格式。
?
2、數據查詢
curl 'localhost:9200/accounts/person/4?pretty'系統返回:
{"_index" : "accounts","_type" : "person","_id" : "4","_version" : 1,"found" : true,"_source" : {"user" : "李四","title" : "軟件工程師","desc" : "系理集成"} }說明查詢成功。如果查詢一個不存在id的記錄,如命令:
curl 'localhost:9200/accounts/person/5?pretty'id等于5的person因為沒有對應的記錄,所以,系統返回:
{"_index" : "accounts","_type" : "person","_id" : "5","found" : false }?
3、刪除記錄
刪除記錄就是發出 DELETE 請求。
?
轉載于:https://www.cnblogs.com/dyh004/p/8917121.html
總結
以上是生活随笔為你收集整理的elasticsearch简单操作(一)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java匿名内部类举例和内部类举例
- 下一篇: Mato的文件管理 (莫队)题解