Elastic Search 6嵌套查询聚合 [英] Elastic Search 6 Nested Query Aggregations
问题描述
我是弹性搜索查询和聚合的新手.我有一个具有以下映射的嵌套文档
PUT/公司{映射":{`数据":{特性": {"deptId":{"type":关键字"},"deptName":{"type":关键字"},员工": {"type":嵌套",特性": {"empId":{"type":关键字"},"empName":{"type":文字"},薪水": {"type":"float"}}}}}}}
我已按如下所示插入示例数据
PUT公司/数据/1{"deptId":"1","deptName":"HR",员工": [{"empId":"1","empName":"John",工资":"1000"},{"empId":"2","empName":将",薪水":"2000"}]}PUT公司/数据/3{"deptId":"3","deptName":"FINANCE",员工": [{"empId":"1","empName":"John",工资":"1000"},{"empId":"2","empName":将",薪水":"2000"},{"empId":"3","empName":标记",薪水":"4000"}]}
如何为以下内容构建查询DSL
- 员工人数最多的部门
- 大多数部门的员工
我正在使用Elastic Search 6.2.4
您的第一个问题答案在此链接中 这回答了您的第二个问题,同时还在阅读附件中的链接. 阅读嵌套的Agg > 我希望这能为您提供所需的东西. i am new to elastic search Query and aggregation.
I have a nested document with the following mapping I have inserted Sample Data as follows How can i Construct a Query DSL for the following I am using Elastic Search 6.2.4 Your First Questions answer is in this link nested inner doc count Which Stats This Answers your Second Question there is also reading the link attached. I hope this gives you what you need. 这篇关于Elastic Search 6嵌套查询聚合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
GET/my_index/blogpost/_search{大小":0,"aggs":{员工": {嵌套":{路径":雇员"},"aggs":{按名字": {条款":{字段":"employee.empName"}}}}}}
PUT /company
{
"mappings": {
`"data": {
"properties": {
"deptId": {
"type": "keyword"
},
"deptName": {
"type": "keyword"
},
"employee": {
"type": "nested",
"properties": {
"empId": {
"type": "keyword"
},
"empName": {
"type": "text"
},
"salary": {
"type": "float"
}
}}}}}}
PUT company/data/1
{
"deptId":"1",
"deptName":"HR",
"employee": [
{
"empId": "1",
"empName": "John",
"salary":"1000"
},
{
"empId": "2",
"empName": "Will",
"salary":"2000"
}
]}
PUT company/data/3
{
"deptId":"3",
"deptName":"FINANCE",
"employee": [
{
"empId": "1",
"empName": "John",
"salary":"1000"
},
{
"empId": "2",
"empName": "Will",
"salary":"2000"
},
{
"empId": "3",
"empName": "Mark",
"salary":"4000"
}]
}
POST test/_search
{
"query": {
"nested": {
"path": "employee",
"inner_hits": {}
}
}
}
GET /my_index/blogpost/_search
{
"size" : 0,
"aggs": {
"employee": {
"nested": {
"path": "employee"
},
"aggs": {
"by_name": {
"terms": {
"field": "employee.empName"
}
}
}
}
}
}