文档 Document
成都创新互联公司致力于互联网网站建设与网站营销,提供成都网站建设、做网站、网站开发、seo优化、网站排名、互联网营销、微信小程序、公众号商城、等建站开发,成都创新互联公司网站建设策划专家,为不同类型的客户提供良好的互联网应用定制解决方案,帮助客户在新的全球化互联网环境中保持优势。
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
}
}
]
}
欢迎加入