?當(dāng)在aggregations中使用嵌套多條件,需要用bool包起來(lái),如果直接在filters[]里寫(xiě),將會(huì)分多個(gè)桶,分別按單個(gè)條件統(tǒng)計(jì);
?部分片段截取:
"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
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? }
? ? ? ? ? ? ]
}
當(dāng)需要將多層嵌套nested用多個(gè)條件AND起來(lái)時(shí):
{
"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
}
}
}
全部片段:文章來(lái)源:http://www.zghlxwxcb.cn/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文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-599281.html
到了這里,關(guān)于Elasticsearch多層嵌套nested查詢和多條件聚合aggregations的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!