App Search - Listing out Categories with Image and Item counts

I have an ElasticSearch Index setup with the following document structure.
NOTE: THIS IS BEING DONE USING APP SEARCH SO I'm UNABLE TO USE NESTED FIELDS

    [
        {
          "id":id,
          "title: "Sample Title",
          "created_at":timestamp
          "categories:[
              {
                  "name": "Category 1"
                  "image": "image.png",
              },
              {
                  "name": "Category 2"
                  "image": "image.png",
              },
              {
                  "name": "Category 3"
                  "image": "image.png",
              },
              {
                  "name": "Category 4"
                  "image": "image.png",
              },
              ....
          ]
        },
        ....
    ]

This index will contain hundreds of thousands of records in this format.
I'm trying to figure out how to optimally setup a query and structure this data so I can setup a query that will allow me to display a list of categories to the end user in this fashion.

  • [image] Category 1 (20)
  • [image] Category 2 (30)
  • [image] Category 3 (10)

This query would be able to be filtered by the created_at timestamp so that the counts would adjust based on the number of items like such.

  • [image] Category 1 (10)
  • [image] Category 2 (5)
  • [image] Category 3 (25)

Using Aggregations to accomplish this gets me very close, but I'm unable to figure out what the category image would be because the aggregations don't bring back anything but a single value and the count.

Thank you!

Hi @selectedpixel

I updated your title and tags so hopefully an App Search person may take a look.

I ended up using an explicit mapping on the category property with a type of "nested". Past that I used a composite aggregation to return a list of buckets with values that contained a key that have the category name, id and image reference.

You can see this SO post for a few more details.

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