当在aggregations中使用嵌套多条件,需要用bool包起来,如果直接在filters[]里写,将会分多个桶,分别按单个条件统计;
部分片段截取:
"filters": {
"filters": [
{
"bool": {
"filter": [
{
"terms": {
"timePeriodList.timePeriod": [
0
],
"boost": 1
}
},
{
"range": {
"timePeriodList.freeDuration": {
"from": 60,
"to": null,
"include_lower": true,
"include_upper": true,
"boost": 1
}
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
}
]
}
当需要将多层嵌套nested用多个条件AND起来时:
{
"nested": {
"query": {
"bool": {
"filter": [
{
"terms": {
"timePeriodList.timePeriod": [
0
],
"boost": 1
}
},
{
"range": {
"timePeriodList.freeDuration": {
"from": 60,
"to": null,
"include_lower": true,
"include_upper": true,
"boost": 1
}
}
},
{
"nested": {
"query": {
"bool": {
"filter": [
{
"term": {
"timePeriodList.skuPriceList.priceDuration": {
"value": 60,
"boost": 1
}
}
},
{
"term": {
"timePeriodList.skuPriceList.standardType": {
"value": "CPT",
"boost": 1
}
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
},
"path": "timePeriodList.skuPriceList",
"ignore_unmapped": false,
"score_mode": "none",
"boost": 1
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
},
"path": "timePeriodList",
"ignore_unmapped": false,
"score_mode": "none",
"boost": 1
}
}
}
全部片段:文章来源:https://www.toymoban.com/news/detail-599281.html
GET entity_point_sku/_search
{
"from": 0,
"size": 0,
"timeout": "60s",
"query": {
"bool": {
"filter": [
{
"term": {
"operatorType": {
"value": "CINEMA",
"boost": 1
}
}
},
{
"term": {
"saleModel": {
"value": "SPLIT",
"boost": 1
}
}
},
{
"range": {
"pointDate": {
"from": "2022-09-10",
"to": "2022-09-10",
"include_lower": true,
"include_upper": true,
"boost": 1
}
}
},
{
"range": {
"freeDuration": {
"from": 60,
"to": null,
"include_lower": true,
"include_upper": true,
"boost": 1
}
}
},
{
"terms": {
"city": [
"440400"
],
"boost": 1
}
},
{
"term": {
"resourceEntityInfoId": {
"value": "be6de436aaa2404d93517dd64ff1facb",
"boost": 1
}
}
},
{
"term": {
"resourcePointId": {
"value": "1a4a487bc5e54b8f9d592030012d6ad5",
"boost": 1
}
}
},
{
"prefix": {
"pointNumber": {
"value": "A",
"boost": 1
}
}
},
{
"nested": {
"query": {
"bool": {
"filter": [
{
"terms": {
"timePeriodList.timePeriod": [
0
],
"boost": 1
}
},
{
"range": {
"timePeriodList.freeDuration": {
"from": 60,
"to": null,
"include_lower": true,
"include_upper": true,
"boost": 1
}
}
},
{
"nested": {
"query": {
"bool": {
"filter": [
{
"term": {
"timePeriodList.skuPriceList.priceDuration": {
"value": 60,
"boost": 1
}
}
},
{
"term": {
"timePeriodList.skuPriceList.standardType": {
"value": "CPT",
"boost": 1
}
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
},
"path": "timePeriodList.skuPriceList",
"ignore_unmapped": false,
"score_mode": "none",
"boost": 1
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
},
"path": "timePeriodList",
"ignore_unmapped": false,
"score_mode": "none",
"boost": 1
}
}
],
"must_not": [
{
"terms": {
"antiIndustry": [
"MEDICAL_KQK"
],
"boost": 1
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
},
"aggregations": {
"resourcePointId_Count": {
"value_count": {
"field": "resourcePointId"
}
},
"pointDateReachTime_Sum": {
"sum": {
"field": "pointDateReachTime"
}
},
"timePeriodList_Name": {
"nested": {
"path": "timePeriodList"
},
"aggregations": {
"timePeriodList_FilterAgg": {
"filters": {
"filters": [
{
"bool": {
"filter": [
{
"terms": {
"timePeriodList.timePeriod": [
0
],
"boost": 1
}
},
{
"range": {
"timePeriodList.freeDuration": {
"from": 60,
"to": null,
"include_lower": true,
"include_upper": true,
"boost": 1
}
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
}
],
"other_bucket": false,
"other_bucket_key": "_other_"
},
"aggregations": {
"timePeriodList.skuPriceList_Name": {
"nested": {
"path": "timePeriodList.skuPriceList"
},
"aggregations": {
"timePeriodList.skuPriceList_FilterAgg": {
"filters": {
"filters": [
{
"bool": {
"filter": [
{
"term": {
"timePeriodList.skuPriceList.priceDuration": {
"value": 60,
"boost": 1
}
}
},
{
"term": {
"timePeriodList.skuPriceList.standardType": {
"value": "CPT",
"boost": 1
}
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
}
],
"other_bucket": false,
"other_bucket_key": "_other_"
},
"aggregations": {
"salePrice_SUM": {
"sum": {
"field": "timePeriodList.skuPriceList.salePrice"
}
},
"stickerPrice_SUM": {
"sum": {
"field": "timePeriodList.skuPriceList.stickerPrice"
}
}
}
}
}
}
}
}
}
}
}
}
Elasticsearch 多层嵌套nested 多条件聚合aggregations文章来源地址https://www.toymoban.com/news/detail-599281.html
到了这里,关于Elasticsearch多层嵌套nested查询和多条件聚合aggregations的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!