Easticsearch官網《Elasticsearch權威指南》筆記2——文件基本操作
阿新 • • 發佈:2019-02-04
建立文件
PUT /megacorp/employee/1
{
"first_name" : "John",
"last_name" : "Smith",
"age" : 25,
"about" : "I love to go rock climbing",
"interests": [ "sports", "music" ]
}
路徑 /megacorp/employee/1 包含了三部分的資訊:
- megacorp
索引名稱 - employee
型別名稱 - 1
特定僱員的ID
獲取文件
GET /megacorp/employee/1
返回結果
{
"_index" : "megacorp",
"_type" : "employee",
"_id" : "1",
"_version" : 1,
"found" : true,
"_source" : {
"first_name" : "John",
"last_name" : "Smith",
"age" : 25,
"about" : "I love to go rock climbing",
"interests": [ "sports" , "music" ]
}
}
帶_
的是一系列元資料,_source
是原始的JSON文件
更新文件
PUT /megacorp/employee/1
{
"first_name" : "John",
"last_name" : "Smith",
"age" : 26,
"about" : "I love to go rock climbing",
"interests": [ "sports", "music", "movies" ]
}
再次GET /megacorp/employee/1
返回結果:
{
"_index ": "megacorp",
"_type": "employee",
"_id": "1",
"_version": 2,
"found": true,
"_source": {
"first_name": "John",
"last_name": "Smith",
"age": 26,
"about": "I love to go rock climbing",
"interests": [
"sports",
"music",
"movies"
]
}
}
age
、_version
都發生了變化
刪除文件
DELETE /megacorp/employee/1
head
head
方法確定文件是否存在,但是不能在sense
裡面使用,因為只返回header而不返回JSON文件
簡單搜尋
GET /megacorp/employee/_search
返回結果包括了所有三個文件,放在陣列 hits 中。一個搜尋預設返回十條結果。
搜尋姓氏為 Smith
的僱員
GET /megacorp/employee/_search?q=last_name:Smith