PUT localhost:9200/accounts/person/1
{
"user": "张三",
"title": "工程师",
"desc": "数据库管理"
}
{
"_index": "accounts",
"_type": "person",
"_id": "1",
"_version": 1,
"result": "created",
"_shards": {
"total": 2,
"successful": 2,
"failed": 0
},
"_seq_no": 0,
"_primary_term": 1
}
POST localhost:9200/accounts/person
{
"user": "李四",
"title": "工程师",
"desc": "系统管理"
}
{
"_index": "accounts",
"_type": "person",
"_id": "3CEKZmUBGSRFZPmXxRma",
"_version": 1,
"result": "created",
"_shards": {
"total": 2,
"successful": 2,
"failed": 0
},
"_seq_no": 2,
"_primary_term": 1
}
GET localhost:9200/accounts/person/1?pretty=true
{
"_index": "accounts",
"_type": "person",
"_id": "1",
"_version": 2,
"found": true,
"_source": {
"user": "张三",
"title": "工程师",
"desc": "数据库管理"
}
}
{
"_index": "accounts",
"_type": "person",
"_id": "2",
"found": false
}
DELETE localhost:9200/accounts/person/1
{
"_index": "accounts",
"_type": "person",
"_id": "1",
"_version": 3,
"result": "deleted",
"_shards": {
"total": 2,
"successful": 2,
"failed": 0
},
"_seq_no": 3,
"_primary_term": 1
}
PUT localhost:9200/accounts/person/1
{
"user" : "张三",
"title" : "工程师",
"desc" : "数据库管理,软件开发"
}
{
"_index": "accounts",
"_type": "person",
"_id": "1",
"_version": 1,
"result": "created",
"_shards": {
"total": 2,
"successful": 2,
"failed": 0
},
"_seq_no": 4,
"_primary_term": 1
}
localhost:9200/accounts/person/_search
{
"took": 261,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 1,
"hits": [
{
"_index": "accounts",
"_type": "person",
"_id": "3CEKZmUBGSRFZPmXxRma",
"_score": 1,
"_source": {
"user": "李四",
"title": "工程师",
"desc": "系统管理"
}
},
{
"_index": "accounts",
"_type": "person",
"_id": "1",
"_score": 1,
"_source": {
"user": "张三",
"title": "工程师",
"desc": "数据库管理,软件开发"
}
}
]
}
}
返回的记录中,每条记录都有一个_score字段,表示匹配的程序,默认是按照这个字段降序排列。
POST localhost:9200/accounts/person/_search
{
"query" : { "match" : { "desc" : "软件" }}
}
{
"took": 256,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1.1978253,
"hits": [
{
"_index": "accounts",
"_type": "person",
"_id": "1",
"_score": 1.1978253,
"_source": {
"user": "张三",
"title": "工程师",
"desc": "数据库管理,软件开发"
}
}
]
}
}
POST localhost:9200/accounts/person/_search
{
"query" : { "match" : { "desc" : "软件" }},
"size": 1
}
POST localhost:9200/accounts/person/_search
{
"query" : { "match" : { "desc" : "软件" }},
"size": 1,
"from": 1
}