您好,登錄后才能下訂單哦!
文檔 Document
Json Object,有字段(field)組成,常見數(shù)據(jù)類型如下:
每個(gè)文檔都有一個(gè)唯一的ID標(biāo)識
元數(shù)據(jù)(MetaData),用于標(biāo)注文檔相關(guān)信息
單詞詞典(Term Dictionary)是倒排索引的重要組成
倒排列表( Posting List )記錄了單詞對應(yīng)的文檔集合,由倒排索引項(xiàng)( Posting )組成
倒排索引項(xiàng)( Posting )主要包含如下信息:
索引中存儲具有相同結(jié)構(gòu)的文檔(Document)
一個(gè)集群可以有多個(gè)索引,比如:
Elasticsearch 集群對外提供RESTful API
es有專門的Index API,用于創(chuàng)建,更新,刪除索引配置等
PUT /test_index
GET_cat/indices
es有專門的 Document API
指定文檔ID創(chuàng)建文檔:
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允許一次操作多個(gè)文檔(增刪改查,create創(chuàng)建文檔,如果文檔已經(jīng)存在就會報(bào)錯。index創(chuàng)建文檔,如果存在就會覆蓋。)
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, //查詢耗時(shí),單位ms
"errors": false, //返回結(jié)果,正確或錯誤
"items": [ //每個(gè)操作返回的結(jié)果
{
"index": {
"_index": "test_index",
"_type": "doc",
"_id": "3",
"_version": 1,
"result": "created", //創(chuàng)建
"_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
}
}
]
}
歡迎加入
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。