# Nested data objects in Elasticsearch index

## Overview

To support displaying and filtering by notices, [an explicit schema](review-queue-schema.jsonc) can be set
on the review queue index, using the `nested` datatype for notices.

> Note: the `flattened` datatype works well for our use-case, but is unavailable
> in AWS's version of Elasticsearch

Notices can have a standardized set of fields that can be queried against:

```jsonc
{
    // ...
    "notices": [
        {
            "level": "error|warning",
            "code": "SOME_NOTICE_CODE",
            "reason": "some reason text..."
        }
    ]
}
```

Using dot-notation, queries can then use the `match` directive to filter by
specific notice codes, like in [this query body](search.jsonc)

## Notes on testing

A local ES cluster can be brought up using `docker_compose up -d`.
Bulk data can be generated with [generate_product.py](generated_products.py) and
submitted to the local cluster via curl

```sh
# Bring up docker stack
docker-compose up -d

# Generate data
python -m venv env
env/bin/python -m pip install -r requirements.txt
env/bin/python generate_products.py > bulk-products.json

# Add data to local ES
cp .env.shadow .env
# Update values in .env file
./load_data.sh

# Clean up env
rm -rf tmp env
docker-compose down

```
