我使用的是kibana内置的开发者工具(Dev Tools)
输入如下语句,点击运行
PUT person/doc/grade1
{
"name":"code",
"grade":90
}
可以看到输出
{
"_index" : "person",
"_type" : "doc",
"_id" : "grade1",
"_version" : 5,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 9,
"_primary_term" : 1
}
为了方便进行查询演示,我们再添加2条数据
PUT person/doc/grade2
{
"name":"teste",
"grade":80
}
PUT person/doc/grade3
{
"name":"product",
"grade":30
}
GET person/doc/grade1
可以看到查询结果为:
{
"_index" : "person",
"_type" : "doc",
"_id" : "grade1",
"_version" : 5,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 9,
"_primary_term" : 1
}
我们以查询分数为80的记录为例进行查询
GET person/doc/_search?q=grade:80
我们可以看到查询结果为:
{
"took" : 7,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "person",
"_type" : "doc",
"_id" : "grade2",
"_score" : 1.0,
"_source" : {
"name" : "teste",
"grade" : 80
}
}
]
}
}
GET person/doc/_search
{
"query":{
"match": {
"grade": 80
}
}
}
查询结果:
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "person",
"_type" : "doc",
"_id" : "grade2",
"_score" : 1.0,
"_source" : {
"name" : "teste",
"grade" : 80
}
}
]
}
}
修改第一条数据的grade字段的值为100
POST person/doc/grade1/_update
{
"doc":{
"grade":100
}
}
结果显示成功:
{
"_index" : "person",
"_type" : "doc",
"_id" : "grade1",
"_version" : 6,
"result" : "updated",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 10,
"_primary_term" : 1
}
DELETE person/doc/grade1
结果显示成功:
{
"_index" : "person",
"_type" : "doc",
"_id" : "grade1",
"_version" : 7,
"result" : "deleted",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 11,
"_primary_term" : 1
}