使用Kibana dev Tools 实现ElasticSearch文档的检索

比眉伴天荒 2023-03-03 05:59 75阅读 0赞

1 查询所有索引

  1. GET _search
  2. {
  3. "query": {
  4. "match_all": { }
  5. }
  6. }

返回结果如下图所示:

  1. {
  2. "took" : 46,
  3. "timed_out" : false,
  4. "_shards" : {
  5. "total" : 20,
  6. "successful" : 20,
  7. "skipped" : 0,
  8. "failed" : 0
  9. },
  10. "hits" : {
  11. "total" : {
  12. "value" : 10000,
  13. "relation" : "gte"
  14. },
  15. "max_score" : 1.0,
  16. "hits" : [
  17. {
  18. "_index" : ".kibana-event-log-7.8.0-000001",
  19. "_type" : "_doc",
  20. "_id" : "S1xHbHMBHlOTuWE2D6Um",
  21. "_score" : 1.0,
  22. "_source" : {
  23. "event" : {
  24. "provider" : "eventLog",
  25. "action" : "starting"
  26. },
  27. "message" : "eventLog starting",
  28. "@timestamp" : "2020-07-20T12:51:02.763Z",
  29. "ecs" : {
  30. "version" : "1.5.0"
  31. },
  32. "kibana" : {
  33. "server_uuid" : "99afcd1f-c893-4d8b-95ae-626a0771cd82"
  34. }
  35. }
  36. }
  37. ]
  38. }
  39. }

在这里插入图片描述

2 返回参数定义:

  • took: 执行搜索耗时,毫秒为单位
  • time_out: 搜索是否超时
  • _shards: 多少分片被搜索,成功多少,失败多少
  • hits: 搜索结果展示
  • hits.total: 匹配条件的文档总数
  • hits.hits: 返回结果展示,默认返回十个
  • hits.max_score:最大匹配得分
  • hits._score: 返回文档的匹配得分(得分越高,匹配程度越高,越靠前)
  • _index 、_type、 _id 作为剥层定位到特定的文档
  • _source 文档源

3 条件查询

3.1 查询所有索引中的地址名称

  1. GET _search
  2. {
  3. "query": {
  4. "match": {
  5. "addressName": "金融大街"
  6. }
  7. }
  8. }

返回结果如下:
在这里插入图片描述

3.2 查询指定索引下的地址名称

  1. GET /test_data_jiangsu/_search
  2. {
  3. "query": {
  4. "match": {
  5. "ADDRESSNAME": "江苏省连云港市连云区墟沟街道长宁路长宁路社区4号楼1单元"
  6. }
  7. }
  8. }

返回结果如下图:
在这里插入图片描述

3.3 查询指定索引的部分字段

  1. POST /test_data_jiangsu/_search
  2. {
  3. "query": {
  4. "match_all": {
  5. } },
  6. "_source": ["ADDRESSCODE", "ADDRESSNAME"]
  7. }

返回结果如下图:
在这里插入图片描述

3.4 查询指定索引中地址名称包括A或者B的文档

  1. POST /test_data_jiangsu/_doc/_search
  2. {
  3. "query": {
  4. "bool": {
  5. "should": [
  6. { "match": { "ADDRESSNAME": "江苏省连云港市1单元"} },
  7. { "match": { "ADDRESSNAME": "江苏省连云港市连云区墟沟街道长宁路长宁路社区4号楼2单元" } }
  8. ]
  9. }
  10. }
  11. }

返回结果如下:
在这里插入图片描述

3.5 查询指定索引中地址名称包括A和B的文档

  1. POST /test_data_jiangsu/_doc/_search
  2. {
  3. "query": {
  4. "bool": {
  5. "must": [
  6. { "match": { "ADDRESSNAME": "江苏省连云港市"} },
  7. { "match": { "ADDRESSNAME": "长宁路社区4号楼2单元" } }
  8. ]
  9. }
  10. }
  11. }

返回结果如下:
在这里插入图片描述

发表评论

表情:
评论列表 (有 0 条评论,75人围观)

还没有评论,来说两句吧...

相关阅读