文档 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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。