Filters Aggregation performance

Hello,

I have a performance issue regarding the next query.
For some context i have a products index on which I have to perform several queries and aggregations based on a configurable set of filters.
Now, my index has the following field sizes: keywords, which contains: ["S", "M", "30A", 30B"]. (like 50 values.

I have the following query on which i used the query profiler on kibana and it says that the bra_cup_size aggregation takes a long time 60ms on collect part and I don't know what to do. Can you help ?

I couldn't add the whole query, because is too big, but imagine that in bra_cup_size we have a filter for sizes from 30A - 44A (A,B,C,D,E,F,G,H,I, and AA) like i think they are 50 , but for the moment they want configurable filter value and relation between sizes, so this is why is so long.

{
  "_source": false,
  "aggregations": {

    "bra_cup_size": {
      "filters": {
        "filters": {
  
          
          "46d": {
            "bool": {
              "filter": [
                {
                  "terms": {
                    "sizes": [
                      "46D",
                      "4X"
                    ]
                  }
                },
                {
                  "terms": {
                    "class": [
                      "bra",
                      "lingerie",
                      "swimwear",
                      "activewear",
                      "corset"
                    ]
                  }
                }
              ]
            }
          },
          "46dd": {
            "bool": {
              "filter": [
                {
                  "terms": {
                    "sizes": [
                      "46DD",
                      "4X"
                    ]
                  }
                },
                {
                  "terms": {
                    "class": [
                      "bra",
                      "lingerie",
                      "swimwear",
                      "activewear",
                      "corset"
                    ]
                  }
                }
              ]
            }
          },
          "46ddd": {
            "bool": {
              "filter": [
                {
                  "terms": {
                    "sizes": [
                      "46DDD",
                      "4X"
                    ]
                  }
                },
                {
                  "terms": {
                    "class": [
                      "bra",
                      "lingerie",
                      "swimwear",
                      "activewear",
                      "corset"
                    ]
                  }
                }
              ]
            }
          },
          "4x": {
            "bool": {
              "filter": {
                "terms": {
                  "sizes": [
                    "4X",
                    "44DDD",
                    "44G",
                    "46C",
                    "46DD",
                    "46DDD"
                  ]
                }
              }
            }
          },
          "l": {
            "bool": {
              "filter": {
                "terms": {
                  "sizes": [
                    "L",
                    "34DD",
                    "34DDD",
                    "36B",
                    "36C"
                  ]
                }
              }
            }
          },
          "m": {
            "bool": {
              "filter": {
                "terms": {
                  "sizes": [
                    "M",
                    "32DD",
                    "32DDD",
                    "34C",
                    "34D",
                    "36A"
                  ]
                }
              }
            }
          },
          "o-s": {
            "bool": {
              "filter": {
                "terms": {
                  "sizes": [
                    "O/S"
                  ]
                }
              }
            }
          },
          "s": {
            "bool": {
              "filter": {
                "terms": {
                  "sizes": [
                    "S",
                    "30D",
                    "30DD",
                    "30DDD",
                    "32B",
                    "32C",
                    "32D",
                    "34A",
                    "34B"
                  ]
                }
              }
            }
          },
          "xl": {
            "bool": {
              "filter": {
                "terms": {
                  "sizes": [
                    "XL",
                    "36D",
                    "36DD",
                    "36DDD",
                    "38B",
                    "38C",
                    "38D"
                  ]
                }
              }
            }
          },
          "xs": {
            "bool": {
              "filter": {
                "terms": {
                  "sizes": [
                    "XS",
                    "30A",
                    "30B",
                    "30C",
                    "32A"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "bra_shape": {
      "aggregations": {
        "selected": {
          "filters": {
            "filters": [
              {
                "bool": {
                  "filter": {
                    "bool": {
                      "filter": {
                        "terms": {
                          "sizes": [
                            "XS",
                            "30A",
                            "30B",
                            "30C",
                            "32A"
                          ]
                        }
                      }
                    }
                  }
                }
              }
            ]
          }
        }
      },
      "filters": {
        "filters": {
          "balconette": {
            "bool": {
              "filter": [
                {
                  "terms": {
                    "class": [
                      "bra"
                    ]
                  }
                },
                {
                  "terms": {
                    "top_shapes": [
                      "Balconette"
                    ]
                  }
                }
              ]
            }
          },
        
          "wirefree": {
            "bool": {
              "filter": [
                {
                  "terms": {
                    "class": [
                      "bra"
                    ]
                  }
                },
                {
                  "terms": {
                    "top_shapes": [
                      "Wirefree"
                    ]
                  }
                }
              ]
            }
          }
        }
      }
    },
    "class-class": {
      "aggregations": {
        "selected": {
          "filters": {
            "filters": [
              {
                "bool": {
                  "filter": {
                    "bool": {
                      "filter": {
                        "terms": {
                          "sizes": [
                            "XS",
                            "30A",
                            "30B",
                            "30C",
                            "32A"
                          ]
                        }
                      }
                    }
                  }
                }
              }
            ]
          }
        }
      },
      "terms": {
        "field": "class",
        "size": 1000
      }
    },
    "collection-collections": {
      "aggregations": {
        "selected": {
          "filters": {
            "filters": [
              {
                "bool": {
                  "filter": {
                    "bool": {
                      "filter": {
                        "terms": {
                          "sizes": [
                            "XS",
                            "30A",
                            "30B",
                            "30C",
                            "32A"
                          ]
                        }
                      }
                    }
                  }
                }
              }
            ]
          }
        }
      },
      "terms": {
        "field": "collections",
        "size": 1000
      }
    },
    "color-colors": {
      "aggregations": {
        "selected": {
          "filters": {
            "filters": [
              {
                "bool": {
                  "filter": {
                    "bool": {
                      "filter": {
                        "terms": {
                          "sizes": [
                            "XS",
                            "30A",
                            "30B",
                            "30C",
                            "32A"
                          ]
                        }
                      }
                    }
                  }
                }
              }
            ]
          }
        }
      },
      "terms": {
        "field": "colors",
        "size": 1000
      }
    },
    "lifestyle-lifestyles": {
      "aggregations": {
        "selected": {
          "filters": {
            "filters": [
              {
                "bool": {
                  "filter": {
                    "bool": {
                      "filter": {
                        "terms": {
                          "sizes": [
                            "XS",
                            "30A",
                            "30B",
                            "30C",
                            "32A"
                          ]
                        }
                      }
                    }
                  }
                }
              }
            ]
          }
        }
      },
      "terms": {
        "field": "lifestyles",
        "size": 1000
      }
    }
  },
  "docvalue_fields": [
    "amid",
    "id"
  ],
  "post_filter": {
    "bool": {
      "filter": {
        "bool": {
          "filter": {
            "terms": {
              "sizes": [
                "XS",
                "30A",
                "30B",
                "30C",
                "32A"
              ]
            }
          }
        }
      }
    }
  },
  "query": {
    "bool": {
      "filter": [
        {
          "term": {
            "status": "enabled"
          }
        },
        {
          "bool": {
            "must_not": {
              "term": {
                "is_sold_out": true
              }
            }
          }
        },
        {
          "range": {
            "quantity": {
              "from": 0,
              "include_lower": false,
              "include_upper": true,
              "to": null
            }
          }
        }
      ]
    }
  },
  "size": 1000
}

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.