#!/bin/bash

# Set your MeiliSearch API key
API_KEY="YoUrV3ry-S3cur3-aP1k3Y"

# Set your MeiliSearch instance URL
MEILISEARCH_URL="http://127.0.0.1:7700"

# Set the index name
INDEX_NAME="products_index"

# Set the attribute you want to make sortable
SORTABLE_ATTRIBUTE='"created_at","min_price","name"'

# Create JSON payload for settings update
SETTINGS_JSON='{
  "sortableAttributes": ['$SORTABLE_ATTRIBUTE']
}'

# Update index settings using cURL
curl -X PATCH "$MEILISEARCH_URL/indexes/$INDEX_NAME/settings" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $API_KEY" \
  -d "$SETTINGS_JSON"
