Elasticsearch-响应内容说明

前言

本文基于elasticsearch7.3.0版本

响应内容说明

本地先创建一个索引, 然后查询

# 创建索引
PUT my_index
{
    
    
  "mappings": {
    
    
    "properties": {
    
    
      "tag": {
    
    
        "type": "keyword"
      }
    }
  }
}

# 插入文档
PUT my_index/_doc/1
{
    
    
  "tag": "水果"
}

# 查询
GET my_index/_search
{
    
    
  "query": {
    
    
    "match_all": {
    
    }
  },
  "aggs": {
    
    
    "tag_terms": {
    
    
      "terms": {
    
    
        "field": "tag"
      }
    }
  }
}

响应

{
    
    
  // elasticsearch查询和聚合耗时(毫秒)
  "took" : 5,
  // 查询和聚合是否超时
  "timed_out" : false,
  // 查询和聚合了多少分片
  "_shards" : {
    
    
  	// 总分片数
    "total" : 1,
    // 成功的分片数
    "successful" : 1,
    // 跳过的分片数
    "skipped" : 0,
    // 失败的分片数
    "failed" : 0
  },
  // 跨集群搜索和聚合时, 包含以下集群信息
  // "_clusters": {
    
    
  // 总集群数
  // "total": 1,
  // 成功的集群数
  // "successful": 1,
  // 跳过的集群数
  // "skipped": 0
  // },
  // 查询信息
  "hits" : {
    
    
    "total" : {
    
    
      // 找到了多少份匹配文档
      "value" : 1,
      "relation" : "eq"
    },
    // 最大的文档最大得分
    "max_score" : 1.0,
    // 默认情况下,hits响应部分包括与搜索标准匹配的前10份文档:
    "hits" : [
      {
    
    
      	// 文档索引, 跨集群查询时显示为:集群名:索引名  eg:(cluster_one:my_index)
        "_index" : "my_index",
        // 文档类型
        "_type" : "_doc",
        // 文档id
        "_id" : "1",
        // 文档得分
        "_score" : 1.0,
        // 文档内容,原样输出(怎么写入就怎么输入)
        "_source" : {
    
    
          "tag" : "水果"
        }
      }
    ]
  },
  // 聚合信息
  "aggregations" : {
    
    
  	// 自定义的聚合名称
    "tag_terms" : {
    
    
      "doc_count_error_upper_bound" : 0,
      "sum_other_doc_count" : 0,
      "buckets" : [
        {
    
    
          "key" : "水果",
          "doc_count" : 1
        }
      ]
    }
  }
}

猜你喜欢

转载自blog.csdn.net/qq_28988969/article/details/103897932