用了Elasticsearch,一口气上5T

elasticsearch nested 是怎么查询 符合条件的的子文档数 最少x个的需求的

Elasticsearch | 作者 zity2050 | 发布于2020年09月01日 | 阅读数:2671

数据结构如下
{
"properties": {
"enterprise_id": {
"type": "integer"
},
"enterprise_name": {
"type": "text"
},
"staffs": {
"type": "nested",
"properties": {
"staff_id": {
"type": "integer"
},
"staff_name": {
"type": "text"
},
"enterprise_id": {
"type": "integer"
},
"age": {
"type": "integer"
},
"post": {
"type": "text"
}
}
}
}
}

 数据如下
POST jsk_search_enterprise_zhc/_doc
{
"enterprise_id": "1001",
"enterprise_name": "测试公司1",
"staffs":[{
"staff_id": 10001,
"staff_name":"张三",
"enterprise_id": "1001",
"age": 27,
"post": "web前端工程师"
},{
"staff_id": 10004,
"staff_name":"王五",
"enterprise_id": "1001",
"age": 32,
"post": "Android工程师"
},{
"staff_id": 10005,
"staff_name":"赵六",
"enterprise_id": "1001",
"age": 26,
"post": "web前端工程师"
},{
"staff_id": 10008,
"staff_name":"李二",
"enterprise_id": "1001",
"age": 30,
"post": "Java工程师"
}]
}

elasticsearch nested  结构中
是怎么查出 有 2个以上年龄在20~30的web前端工程师的,并且有1个以上年龄在30~40的Java工程师的公司呢 
我初步猜测得用 script 来查询 但具体怎么查询的呢 还没找到类似的案例
 
各位大佬 有什么建议或思路吗 万分感谢!
已邀请:

pony_maggie - 公众号:犀牛饲养员的技术笔记

赞同来自:

脚本是一种方案,另外根据条件查询后在业务代码层自己过滤下也可以

要回复问题请先登录注册