国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Elasticsearch多層嵌套nested查詢和多條件聚合aggregations

這篇具有很好參考價(jià)值的文章主要介紹了Elasticsearch多層嵌套nested查詢和多條件聚合aggregations。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

?當(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
          }
        }
}

全部片段:

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)!

本文來(lái)自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • 6.ELK之Elasticsearch嵌套(Nested)類(lèi)型

    6.ELK之Elasticsearch嵌套(Nested)類(lèi)型

    在Elasticsearch實(shí)際應(yīng)用中經(jīng)常會(huì)遇到嵌套文檔的情況,而且會(huì)有“對(duì)象數(shù)組彼此獨(dú)立地進(jìn)行索引和查詢的訴求”。在ES中這種嵌套文檔稱為父子文檔,父子文檔“彼此獨(dú)立地進(jìn)行查詢”至少有以下兩種方式: 1)父子文檔。在ES的5.x版本中通過(guò)parent-child父子type實(shí)現(xiàn),即一個(gè)索引

    2024年02月03日
    瀏覽(17)
  • ElasticSearch第五講 ES nested嵌套文檔與父子文檔處理

    在ES中,處理實(shí)體之間的關(guān)系并不像關(guān)系型存儲(chǔ)那樣明顯。在關(guān)系數(shù)據(jù)庫(kù)中的黃金準(zhǔn)則 - 數(shù)據(jù)規(guī)范化,在ES中并不適用。在處理關(guān)聯(lián)關(guān)系,嵌套對(duì)象和父子關(guān)聯(lián)關(guān)系中,我們會(huì)討論幾種可行方案的優(yōu)點(diǎn)和缺點(diǎn)。 緊接著在為可擴(kuò)展性而設(shè)計(jì)中,我們會(huì)討論ES提供的一些用來(lái)快速靈

    2024年02月02日
    瀏覽(22)
  • Elasticsearch 8.X 如何依據(jù) Nested 嵌套類(lèi)型的某個(gè)字段進(jìn)行排序?

    Elasticsearch 8.X 如何依據(jù) Nested 嵌套類(lèi)型的某個(gè)字段進(jìn)行排序?

    這是來(lái)自社區(qū)的一個(gè)真實(shí)企業(yè)場(chǎng)景問(wèn)題。 https://elasticsearch.cn/question/13135 如下所示, 希望在查出的結(jié)果后, 對(duì)結(jié)果進(jìn)行后處理,對(duì)tags列表,根據(jù)depth進(jìn)行排序。 Elasticsearch 能支持的排序方式羅列如下: 包含但不限于: 基于特定字段的排序 基于Nested對(duì)象字段的排序 基于特定

    2024年02月02日
    瀏覽(20)
  • SQL-條件查詢與聚合函數(shù)的使用

    SQL-條件查詢與聚合函數(shù)的使用

    ???歡迎您來(lái)到我的MySQL基礎(chǔ)復(fù)習(xí)專(zhuān)欄 ☆* o(≧▽≦)o *☆哈嘍~我是小小惡斯法克?? ?博客主頁(yè): 小小惡斯法克的博客 ??該系列文章專(zhuān)欄: 重拾MySQL ??文章作者技術(shù)和水平很有限,如果文中出現(xiàn)錯(cuò)誤,希望大家能指正?? ?? 感謝大家的關(guān)注!??? 目錄 DQL-條件查詢 1.語(yǔ)法

    2024年01月23日
    瀏覽(21)
  • Elasticsearch--查詢(nested、join)

    Elasticsearch--查詢(nested、join)

    嵌套類(lèi)型 數(shù)據(jù)的某個(gè)值是json、object對(duì)象;不再是簡(jiǎn)單的數(shù)據(jù)類(lèi)型,或者簡(jiǎn)單數(shù)據(jù)類(lèi)型的數(shù)組;那么還用之前的查詢方式就有問(wèn)題了。因?yàn)镋S在存儲(chǔ)復(fù)雜類(lèi)型的時(shí)候會(huì)把對(duì)象的復(fù)雜層次結(jié)果扁平化為一個(gè)鍵值對(duì)列表 。此時(shí),需要用nested進(jìn)行查詢 扁平化存儲(chǔ) ? ?用法 使用nest

    2024年02月16日
    瀏覽(16)
  • MySQL學(xué)習(xí)筆記3——條件查詢和聚合函數(shù)

    MySQL學(xué)習(xí)筆記3——條件查詢和聚合函數(shù)

    WHERE 和 HAVING 的區(qū)別: WHERE是直接對(duì)表中的字段進(jìn)行限定,來(lái)篩選結(jié)果; HAVING則需要跟分組GROUP BY一起使用,通過(guò)對(duì)分組字段或分組計(jì)算函數(shù)進(jìn)行限定,來(lái)篩選結(jié)果。 雖然它們都是對(duì)查詢進(jìn)行限定,卻有著各自的特點(diǎn)和適用場(chǎng)景。 WHERE WHERE的特點(diǎn)是,直接用表的

    2024年04月16日
    瀏覽(40)
  • Spring Boot學(xué)習(xí)隨筆- 集成MyBatis-Plus(二)條件查詢QueryWrapper、聚合函數(shù)的使用、Lambda條件查詢

    Spring Boot學(xué)習(xí)隨筆- 集成MyBatis-Plus(二)條件查詢QueryWrapper、聚合函數(shù)的使用、Lambda條件查詢

    學(xué)習(xí)視頻:【編程不良人】Mybatis-Plus整合SpringBoot實(shí)戰(zhàn)教程,提高的你開(kāi)發(fā)效率,后端人員必備! 普通查詢 條件構(gòu)造器查詢 【重要】 AbstractWrapper ?是 MyBatis Plus 中的一個(gè)抽象類(lèi),用于構(gòu)建 SQL 查詢條件。定義了泛型? T 、 C ?和? Children 。其中, T ?表示實(shí)體類(lèi)的類(lèi)型, C ?表示查

    2024年02月04日
    瀏覽(26)
  • Elasticsearch 基本使用(二)簡(jiǎn)單查詢 & 嵌套查詢

    Elasticsearch 基本使用(二)簡(jiǎn)單查詢 & 嵌套查詢

    按id查詢單條記錄 查詢所有數(shù)據(jù) 默認(rèn)只查詢10條記錄 設(shè)置分頁(yè)條件 設(shè)置排序 兩種設(shè)置方式 注意:_id 為字符串,其排序方式為按位比較,并非數(shù)值大小 filter 過(guò)濾 在 bool 查詢內(nèi),可以使用 filter 對(duì)數(shù)據(jù)進(jìn)行過(guò)濾。 單從最終數(shù)據(jù)來(lái)看,filter 也是用于過(guò)濾數(shù)據(jù),用于條件查詢。

    2024年02月03日
    瀏覽(16)
  • 【JaveWeb教程】(20) MySQL數(shù)據(jù)庫(kù)開(kāi)發(fā)之 基本查詢、條件查詢、聚合函數(shù)、分組查詢、排序查詢、分頁(yè)查詢 詳細(xì)代碼示例講解

    【JaveWeb教程】(20) MySQL數(shù)據(jù)庫(kù)開(kāi)發(fā)之 基本查詢、條件查詢、聚合函數(shù)、分組查詢、排序查詢、分頁(yè)查詢 詳細(xì)代碼示例講解

    在上次學(xué)習(xí)的內(nèi)容中,我們講解了: 使用DDL語(yǔ)句來(lái)操作數(shù)據(jù)庫(kù)以及表結(jié)構(gòu)(數(shù)據(jù)庫(kù)設(shè)計(jì)) 使用DML語(yǔ)句來(lái)完成數(shù)據(jù)庫(kù)中數(shù)據(jù)的增、刪、改操作(數(shù)據(jù)庫(kù)操作) 我們今天還是繼續(xù)學(xué)習(xí)數(shù)據(jù)庫(kù)操作方面的內(nèi)容:查詢(DQL語(yǔ)句)。 查詢操作我們分為兩部分學(xué)習(xí): DQL語(yǔ)句-單表操作

    2024年02月02日
    瀏覽(47)
  • Elasticsearch查詢以及聚合查詢

    must:返回的文檔必須滿足子句的條件,并且參與計(jì)算分值 filter:返回的文檔必須滿足filter子句的條件,不會(huì)參與計(jì)算分值 should:返回的文檔可能滿足should子句的條件。 must_nout:返回的文檔必須不滿足must_not定義的條件。 注意:如果一個(gè)查詢既有filter又有should,那么至少包含

    2023年04月13日
    瀏覽(19)

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包