一、使用Kibana 中 Dev Tools
1. 查询指定索引下的所有数据
http
GET /calvin/_search
查询结果,如下:
json
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 5,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "calvin",
"_type" : "_doc",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"id" : "4",
"_class" : "com.springboot.es.example.domain.User",
"name" : "李四",
"age" : 40,
"sex" : 1
}
},
{
"_index" : "calvin",
"_type" : "_doc",
"_id" : "5",
"_score" : 1.0,
"_source" : {
"id" : "5",
"_class" : "com.springboot.es.example.domain.User",
"name" : "王五",
"age" : 50,
"sex" : 1
}
},
{
"_index" : "calvin",
"_type" : "_doc",
"_id" : "6",
"_score" : 1.0,
"_source" : {
"id" : "6",
"_class" : "com.springboot.es.example.domain.User",
"name" : "赵六",
"age" : 60,
"sex" : 1
}
},
{
"_index" : "calvin",
"_type" : "_doc",
"_id" : "3",
"_score" : 1.0,
"_source" : {
"_class" : "com.springboot.es.example.domain.User",
"id" : "3",
"name" : "张三",
"age" : 30,
"sex" : 1
}
},
{
"_index" : "calvin",
"_type" : "_doc",
"_id" : "2",
"_score" : 1.0,
"_source" : {
"_class" : "com.springboot.es.example.domain.User",
"id" : "2",
"name" : "小二",
"age" : 25,
"sex" : 1
}
}
]
}
}
2. 查询指定索引下,根据ID查询单个数据
http
GET /calvin/_doc/2
查询结果,如下:
json
{
"_index" : "calvin",
"_type" : "_doc",
"_id" : "2",
"_version" : 5,
"_seq_no" : 17,
"_primary_term" : 1,
"found" : true,
"_source" : {
"_class" : "com.springboot.es.example.domain.User",
"id" : "2",
"name" : "小二",
"age" : 25,
"sex" : 1
}
}
3. 根据指定索引下,根据多个ID进行列表查询
http
GET /calvin/_mget
{
"ids":["2", "3", "4"]
}
查询结果,如下:
json
{
"docs" : [
{
"_index" : "calvin",
"_type" : "_doc",
"_id" : "2",
"_version" : 5,
"_seq_no" : 17,
"_primary_term" : 1,
"found" : true,
"_source" : {
"_class" : "com.springboot.es.example.domain.User",
"id" : "2",
"name" : "小二",
"age" : 25,
"sex" : 1
}
},
{
"_index" : "calvin",
"_type" : "_doc",
"_id" : "3",
"_version" : 2,
"_seq_no" : 15,
"_primary_term" : 1,
"found" : true,
"_source" : {
"_class" : "com.springboot.es.example.domain.User",
"id" : "3",
"name" : "张三",
"age" : 30,
"sex" : 1
}
},
{
"_index" : "calvin",
"_type" : "_doc",
"_id" : "4",
"found" : false
}
]
}
4. 根据指定索引下,根据某个字段进行列表查询
http
GET /calvin/_search?q=age:25
查询结果,如下:
json
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "calvin",
"_type" : "_doc",
"_id" : "2",
"_score" : 1.0,
"_source" : {
"_class" : "com.springboot.es.example.domain.User",
"id" : "2",
"name" : "小二",
"age" : 25,
"sex" : 1
}
}
]
}
}
5. 根据指定索引下,根据某个字段进行条件范围查询
http
GET /calvin/_search?q=age[25 TO 40 ]
查询结果,如下:
json
{
"took" : 4,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 3,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "calvin",
"_type" : "_doc",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"id" : "4",
"_class" : "com.springboot.es.example.domain.User",
"name" : "李四",
"age" : 40,
"sex" : 1
}
},
{
"_index" : "calvin",
"_type" : "_doc",
"_id" : "3",
"_score" : 1.0,
"_source" : {
"_class" : "com.springboot.es.example.domain.User",
"id" : "3",
"name" : "张三",
"age" : 30,
"sex" : 1
}
},
{
"_index" : "calvin",
"_type" : "_doc",
"_id" : "2",
"_score" : 1.0,
"_source" : {
"_class" : "com.springboot.es.example.domain.User",
"id" : "2",
"name" : "小二",
"age" : 25,
"sex" : 1
}
}
]
}
}
6. 根据指定索引下,字段筛选条件、排序条件进行分页查询
http
GET /calvin/_search?q=age[25 TO 50 ]&sort=age:desc&from=0&size=2
查询结果,如下:
json
{
"took" : 4,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 4,
"relation" : "eq"
},
"max_score" : null,
"hits" : [
{
"_index" : "calvin",
"_type" : "_doc",
"_id" : "5",
"_score" : null,
"_source" : {
"id" : "5",
"_class" : "com.springboot.es.example.domain.User",
"name" : "王五",
"age" : 50,
"sex" : 1
},
"sort" : [
50
]
},
{
"_index" : "calvin",
"_type" : "_doc",
"_id" : "1",
"_score" : null,
"_source" : {
"id" : "4",
"_class" : "com.springboot.es.example.domain.User",
"name" : "李四",
"age" : 40,
"sex" : 1
},
"sort" : [
40
]
}
]
}
}