【kibana】es的数据库查询
3.插入指定的行_id,并更新指定_id的文档。5.查看数据库元数据信息。
·
1.关闭数据库
POST /myindex15/_close
--查询数据库
get myindex15/_search
--关闭后将无法查询。
{
"error" : {
"root_cause" : [
{
"type" : "index_closed_exception",
"reason" : "closed",
"index_uuid" : "EJwz5QEyQqatU34YmfHDtQ",
"index" : "myindex15"
}
],
"type" : "index_closed_exception",
"reason" : "closed",
"index_uuid" : "EJwz5QEyQqatU34YmfHDtQ",
"index" : "myindex15"
},
"status" : 400
}
2.打开数据库
POST /myindex15/_open
--查询数据库,可以正常查询。
get myindex15/_search
3.插入指定的行_id,并更新指定_id的文档
(1)插入
put /myindex5/_doc/8
{
"doc": {
"id" : "8",
"name" : "myname8",
"city" : "深圳",
"course" : "greenplum",
"teacher" : "xsq",
"pxdate": "20240628"
}
}
get myindex5/_search
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "myindex5",
"_type" : "_doc",
"_id" : "8",
"_score" : 1.0,
"_source" : {
"doc" : {
"id" : "8",
"name" : "myname8",
"city" : "深圳",
"course" : "greenplum",
"teacher" : "xsq",
"pxdate" : "20240628"
}
}
}
]
}
}
(2)更新 teacher="xsq2",city="北京"
POST /myindex5/_update/8
{
"doc": {
"city" : "北京",
"teacher" : "xsq2"
}
}
--更新前后的值都在。
get myindex5/_search
{
"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" : "myindex5",
"_type" : "_doc",
"_id" : "8",
"_score" : 1.0,
"_source" : {
"doc" : {
"id" : "8",
"name" : "myname8",
"city" : "深圳",
"course" : "greenplum",
"teacher" : "xsq",
"pxdate" : "20240628"
},
"teacher" : "xsq2",
"city" : "北京"
}
}
]
}
}
4.查询文档
get myindex5/_doc/8
{
"_index" : "myindex5",
"_type" : "_doc",
"_id" : "8",
"_version" : 2,
"_seq_no" : 1,
"_primary_term" : 1,
"found" : true,
"_source" : {
"doc" : {
"id" : "8",
"name" : "myname8",
"city" : "深圳",
"course" : "greenplum",
"teacher" : "xsq",
"pxdate" : "20240628"
},
"teacher" : "xsq2",
"city" : "北京"
}
}
5.查看数据库元数据信息。
--映射信息及副本信息
get myindex5
--查看所有记录。
GET /myindex5/_search?pretty
GET /myindex5/_search
--查看所有的数据库的字段,副本信息。
GET /_all 或者: GET /* */
--查看设置信息
--副本信息
GET /myindex5/_settings
{
"myindex5" : {
"settings" : {
"index" : {
"creation_date" : "1719559107623",
"number_of_shards" : "1",
"number_of_replicas" : "1",
"uuid" : "_EGl89OrTLeTHE7gW4haAw",
"version" : {
"created" : "7090299"
},
"provided_name" : "myindex5"
}
}
}
}
--查看字段信息
GET /myindex5/_mapping
{
"myindex5" : {
"mappings" : {
"properties" : {
"city" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"doc" : {
"properties" : {
"city" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"course" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"id" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"name" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"pxdate" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"teacher" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
},
"teacher" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
}
}
}
--判断数据库是否存在
--检查不存在的数据库
HEAD myindex6
{"statusCode":404,"error":"Not Found","message":"404 - Not Found"}
--检查存在的数据库
HEAD myindex5
200 - OK
--查询文档_id=8的记录。
GET /myindex5/_doc/8
{
"_index" : "myindex5",
"_type" : "_doc",
"_id" : "8",
"_version" : 2,
"_seq_no" : 1,
"_primary_term" : 1,
"found" : true,
"_source" : {
"doc" : {
"id" : "8",
"name" : "myname8",
"city" : "深圳",
"course" : "greenplum",
"teacher" : "xsq",
"pxdate" : "20240628"
},
"teacher" : "xsq2",
"city" : "北京"
}
}
--全库查询
GET myindex5/_search?pretty
--插入
put myindex5/_doc/7
{
"id":7,
"name":"myname7"
}
--插入
put myindex5/_doc/6
{
"id":6,
"name":"myname6"
}
--插入
put myindex5/_doc/5
{
"id":5,
"name":"myname5",
"city":"北京"
}
--查询指定的记录中,指定的字段。
GET myindex5/_doc/5?_source=id,name
{
"_index" : "myindex5",
"_type" : "_doc",
"_id" : "5",
"_version" : 1,
"_seq_no" : 4,
"_primary_term" : 1,
"found" : true,
"_source" : {
"name" : "myname5",
"id" : 5
}
}
--where条件筛选
GET /myindex5/_search?q=name:myname5
{
"took" : 533,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : 0.9808291,
"hits" : [
{
"_index" : "myindex5",
"_type" : "_doc",
"_id" : "5",
"_score" : 0.9808291,
"_source" : {
"id" : 5,
"name" : "myname5",
"city" : "北京"
}
}
]
}
}
GET /myindex5/_search?q=city:北京
{
"took" : 30,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 2,
"relation" : "eq"
},
"max_score" : 0.36464313,
"hits" : [
{
"_index" : "myindex5",
"_type" : "_doc",
"_id" : "8",
"_score" : 0.36464313,
"_source" : {
"doc" : {
"id" : "8",
"name" : "myname8",
"city" : "深圳",
"course" : "greenplum",
"teacher" : "xsq",
"pxdate" : "20240628"
},
"teacher" : "xsq2",
"city" : "北京"
}
},
{
"_index" : "myindex5",
"_type" : "_doc",
"_id" : "5",
"_score" : 0.36464313,
"_source" : {
"id" : 5,
"name" : "myname5",
"city" : "北京"
}
}
]
}
}
--查询所有记录。
GET myindex5/_search
GET myindex5/_search?pretty
GET myindex5/_search
{
"query": {
"match_all": {}
}
}
--查询指定的字段。
--查询所有,只查询两个字段。
GET myindex5/_search
{
"query": {
"match_all": {}
},
"_source": ["name","city"]
}
--回显
{
"took" : 3,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 4,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "myindex5",
"_type" : "_doc",
"_id" : "8",
"_score" : 1.0,
"_source" : {
"city" : "北京"
}
},
{
"_index" : "myindex5",
"_type" : "_doc",
"_id" : "7",
"_score" : 1.0,
"_source" : {
"name" : "myname7"
}
},
{
"_index" : "myindex5",
"_type" : "_doc",
"_id" : "6",
"_score" : 1.0,
"_source" : {
"name" : "myname6"
}
},
{
"_index" : "myindex5",
"_type" : "_doc",
"_id" : "5",
"_score" : 1.0,
"_source" : {
"city" : "北京",
"name" : "myname5"
}
}
]
}
}
更多推荐
已为社区贡献11条内容
所有评论(0)