title: use $facet with mongoDB $search for filters navigation
body: <p><strong>How can I make brands that don't change with $search when using with filters.</strong></p>
  <pre><code>    const products = await Product.aggregate([
    {
      $search: {
        compound: {
          must: finalQuery,
        },
      },
    },
  
    { $skip: pageSize * (page - 1) },
    { $limit: pageSize },
  
    {
      $project: {
        _id: 1,
        name: 1,
        brand: 1,
        productCollection: 1,
        department: 1,
        category: 1,
        subcategory: 1,
        color: 1,
        price: 1,
        images: 1,
        size_names: 1,
        sizes: 1,
        productType: 1,
        productTag: 1,
        counter: 1,
        discountDisplayLabel: 1,
        discount: 1,
        mrp: 1,
        createdAt: 1,
        tags: 1,
        slug: 1,
        // score: { $meta: &quot;searchScore&quot; },
      },
    },
  ]);
  
  
  const filters = await Product.aggregate([
    {
      $search: {
        compound: {
          must: finalQuery,
        },
      },
    },
    {
      $facet: {
        category_filters: [
          {
            $group: {
              _id: &quot;$category&quot;,
              count: { $sum: 1 },
            },
          },
          { $sort: { count: -1, _id: -1 } },
        ],
        subcategory_filters: [
          {
            $group: {
              _id: &quot;$subcategory&quot;,
              count: { $sum: 1 },
            },
          },
          { $sort: { count: -1, _id: -1 } },
        ],
        brands_filters: [
          {
            $group: {
              _id: &quot;$brandSlug&quot;,
              count: { $sum: 1 },
            },
          },
          { $sort: { count: -1, _id: -1 } },
        ],
  
        size_names_filters: [
          { $limit: 10000 },
          { $unwind: &quot;$sizes&quot; },
          {
            $group: {
              _id: &quot;$sizes.name&quot;,
              count: { $sum: 1 },
            },
          },
          { $sort: { count: -1, _id: -1 } },
        ],
  
        prices_filters: [
          {
            $bucketAuto: {
              groupBy: &quot;$price&quot;,
              buckets: 5,
            },
          },
        ],
      },
    },
  ]);
  </code></pre>
  <p>The output of this:</p>
  <pre><code>{ products:[
  {
              &quot;_id&quot;: &quot;607170bb46d0eb352657b9a1&quot;,
              &quot;productCollection&quot;: [
                  &quot;korean-cosmetics&quot;
              ],
              &quot;productTag&quot;: &quot;NORMAL&quot;,
              &quot;mrp&quot;: 38,
              &quot;price&quot;: 38,
              &quot;discount&quot;: 0,
              &quot;images&quot;: [
                  {
                      &quot;public_id&quot;: &quot;image key&quot;,
                      &quot;url&quot;: &quot;image url&quot;
                  },
          
              ],
              &quot;size_names&quot;: &quot;One Size&quot;,
              &quot;counter&quot;: 2,
              &quot;name&quot;: &quot;Product name&quot;,
              &quot;brand&quot;: &quot;brand name&quot;,
              &quot;category&quot;: &quot;health-and-beauty&quot;,
              &quot;subcategory&quot;: &quot;makeup&quot;,
              &quot;department&quot;: &quot;UNISEX&quot;,
              &quot;productType&quot;: &quot;LIFESTYLE&quot;,
              &quot;color&quot;: &quot;&quot;,
              &quot;sizes&quot;: [
                  {
                      &quot;name&quot;: &quot;One Size&quot;,
                      &quot;sku&quot;: &quot;ABC12&quot;,
                      &quot;quantity&quot;: 2
                  }
              ],
              &quot;createdAt&quot;: &quot;2021-04-10T09:32:43.194Z&quot;,
              &quot;slug&quot;: &quot;propolis-light-cream-65gm&quot;,
              &quot;tags&quot;: [
          
                  &quot;gentle-care&quot;,
                  &quot;unisex&quot;,
                  &quot;designer&quot;,
                  &quot;fashion&quot;,
                  &quot;best&quot;,
                  &quot;100%&quot;,
                  &quot;under&quot;,
                  &quot;affordable&quot;,
                  &quot;beautiful&quot;,
                  &quot;healthy&quot;,
                  &quot;fashion&quot;,
                  &quot;makeup&quot;,
                  &quot;beauty&quot;
              ]
          },
  ],......,
      &quot;filters&quot;: [
          {
              &quot;category_filters&quot;: [
                  {
                      &quot;_id&quot;: &quot;health-and-beauty&quot;,
                      &quot;count&quot;: 51
                  }
              ],
              &quot;subcategory_filters&quot;: [
                  {
                      &quot;_id&quot;: &quot;k-beauty&quot;,
                      &quot;count&quot;: 51
                  }
              ],
              &quot;brands_filters&quot;: [
                  {
                      &quot;_id&quot;: &quot;cosrx&quot;,
                      &quot;count&quot;: 26
                  },
                  {
                      &quot;_id&quot;: &quot;innisfree&quot;,
                      &quot;count&quot;: 8
                  },
                  {
                      &quot;_id&quot;: &quot;laneige&quot;,
                      &quot;count&quot;: 5
                  },
                  {
                      &quot;_id&quot;: &quot;it-s-skin&quot;,
                      &quot;count&quot;: 4
                  },
                  {
                      &quot;_id&quot;: &quot;the-face-shop&quot;,
                      &quot;count&quot;: 3
                  },
                  {
                      &quot;_id&quot;: &quot;dr-jart&quot;,
                      &quot;count&quot;: 3
                  },
                  {
                      &quot;_id&quot;: &quot;tonymoly&quot;,
                      &quot;count&quot;: 2
                  }
              ],
              &quot;size_names_filters&quot;: [
                  {
                      &quot;_id&quot;: &quot;One Size&quot;,
                      &quot;count&quot;: 49
                  },
                  {
                      &quot;_id&quot;: &quot;onesize&quot;,
                      &quot;count&quot;: 2
                  }
              ],
              &quot;prices_filters&quot;: [
                  {
                      &quot;_id&quot;: {
                          &quot;min&quot;: 5,
                          &quot;max&quot;: 17
                      },
                      &quot;count&quot;: 10
                  },
                  {
                      &quot;_id&quot;: {
                          &quot;min&quot;: 17,
                          &quot;max&quot;: 25
                      },
                      &quot;count&quot;: 12
                  },
                  {
                      &quot;_id&quot;: {
                          &quot;min&quot;: 25,
                          &quot;max&quot;: 29
                      },
                      &quot;count&quot;: 13
                  },
                  {
                      &quot;_id&quot;: {
                          &quot;min&quot;: 29,
                          &quot;max&quot;: 39
                      },
                      &quot;count&quot;: 10
                  },
                  {
                      &quot;_id&quot;: {
                          &quot;min&quot;: 39,
                          &quot;max&quot;: 89
                      },
                      &quot;count&quot;: 6
                  }
              ]
          }
      ]
  </code></pre>
  <p>}</p>
  <p>Now if I click brand it should not hide other brands too.</p>
  <p>EXAMPLE- products I am getting are related to  brandX,brandY and brandZ</p>
  <p>when I add brandX filter..</p>
  <p>brandY and brandZ are also being filtered..</p>
  <p>I want to show the results of brandX and its appropriate sizes along with brandY and brandZ still visible in UI</p>