您好,登錄后才能下訂單哦!
文檔 Document
Json Object,有字段(field)組成,常見數據類型如下:
每個文檔都有一個唯一的ID標識
元數據(MetaData),用于標注文檔相關信息
單詞詞典(Term Dictionary)是倒排索引的重要組成
倒排列表( Posting List )記錄了單詞對應的文檔集合,由倒排索引項( Posting )組成
倒排索引項( Posting )主要包含如下信息:
索引中存儲具有相同結構的文檔(Document)
一個集群可以有多個索引,比如:
Elasticsearch 集群對外提供RESTful API
es有專門的Index API,用于創建,更新,刪除索引配置等
PUT /test_index
GET_cat/indices
es有專門的 Document API
指定文檔ID創建文檔:
PUT /test_index/doc/1
{
"username":"kibana",
"version":6.1
}
POST /test1_index/doc
{
"username":"kibana",
"version":6.1
}
GET /test_index/doc/1
GET /test_index/doc/_search //不指定條件查找
GET /test_index/doc/_search
{
"query": {
"term":{
"_id":"1" //指定條件,查找ID為1的文檔
}
}
}
es允許一次操作多個文檔(增刪改查,create創建文檔,如果文檔已經存在就會報錯。index創建文檔,如果存在就會覆蓋。)
POST _bulk
{"index":{"_index":"test_index","_type":"doc","_id":"3"}}
{"username":"zabbix","version":4}
{"delete":{"_index":"test_index","_type":"doc","_id":"1"}}
{"update":{"_id":"4","_index":"test_index","_type":"doc"}}
{"doc":{"es":"5.0"}}
輸出:
{
"took": 979, //查詢耗時,單位ms
"errors": false, //返回結果,正確或錯誤
"items": [ //每個操作返回的結果
{
"index": {
"_index": "test_index",
"_type": "doc",
"_id": "3",
"_version": 1,
"result": "created", //創建
"_shards": {
"total": 2,
"successful": 2,
"failed": 0
},
"_seq_no": 0,
"_primary_term": 1,
"status": 201
}
},
{
"delete": {
"_index": "test_index",
"_type": "doc",
"_id": "1",
"_version": 2,
"result": "deleted", //刪除
"_shards": {
"total": 2,
"successful": 2,
"failed": 0
},
"_seq_no": 1,
"_primary_term": 1,
"status": 200
}
},
{
"update": {
"_index": "test_index",
"_type": "doc",
"_id": "4",
"_version": 2,
"result": "updated", //更改
"_shards": {
"total": 2,
"successful": 2,
"failed": 0
},
"_seq_no": 3,
"_primary_term": 1,
"status": 200
}
}
]
}
GET /_mget //查找在test_index索引,id為4和1的文檔.
{
"docs":[ //指明要查詢的文檔id
{
"_index":"test_index",
"_type":"doc",
"_id":"4"
},
{
"_index":"test_index",
"_type":"doc",
"_id":"2"
}
]
}
返回
{
"docs": [
{
"_index": "test_index",
"_type": "doc",
"_id": "4",
"_version": 2,
"found": true,
"_source": {
"username": "es",
"version": 6.1,
"es": "5.0"
}
},
{
"_index": "test_index",
"_type": "doc",
"_id": "2",
"_version": 1,
"found": true,
"_source": {
"username": "zabbix",
"version": 4.2
}
}
]
}
歡迎加入
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。