繁体   English   中英

Elasticsearch 中的查询聚合

[英]Aggregation on query in Elasticsearch

我在 es 中有索引,这是相应的映射:

'''

 GET /vid_detect2/_mapping
            
        {

            "properties": {
                "date":{"type":"date"},
                "time":{ "type": "text",
                         "fielddata": true},
                "frame_id": {"type":"integer"},
                "camera_id":{"type":"integer"},
                "path":{"type":"text"},
                "objects" : {"type": "nested", 
                             "properties": {
                                            "class":    { "type": "text" ,"fielddata":true },
                                            "confidence": { "type": "float"  },
                                             "coordinates":{ "type": "nested" ,
                                                             "properties": { "x" :{"type":"float"},
                                                                             "y" :{"type":"float"},
                                                                             "w" :{"type":"float"},
                                                                             "h" :{"type":"float"}
                                                             }  }
        
                                            }
                
            }
        
    }
}'''

我想先运行以下查询:

 "query": {
 "bool": {
  "must": [
   {
     "nested": {
    "path": "objects", 
    "query": {
      "bool": {
        "must": [ 
          { "match": { "objects.class": "person" }}
        
        ]
}}}}
]
 }}

然后将返回的结果与 camera_id 进行聚合,并进一步将这些聚合结果与日期直方图进行聚合。 请帮忙。

好的开始:您现在可以简单地添加一个聚合部分来实现您想要的:

{
  "query": {
    "bool": {
      "must": [
        {
          "nested": {
            "path": "objects",
            "query": {
              "bool": {
                "must": [
                  {
                    "match": {
                      "objects.class": "person"
                    }
                  }
                ]
              }
            }
          }
        }
      ]
    }
  },
  "aggs": {
    "camera": {
      "terms": {
        "field": "camera_id"
      },
      "aggs": {
        "histo": {
          "date_histogram": {
            "field": "date",
            "interval": "day"
          }
        }
      }
    }
  }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM