CROP
ProjectsParts Services

Critical Fixes Plan

> Date: 2026-01-23 > Priority: CRITICAL > Status: In Progress

Critical Fixes Plan

Date: 2026-01-23 Priority: CRITICAL Status: In Progress


Identified Issues

🔴 CRITICAL

#IssueImpact
1gcp-rebuild-dev-index.sh includes parts_kmtWill return KMT to parts_current
2ES mapping not applied to live indicesproductType unavailable for filtering
3Data without productTypeFiltering doesn't work
4Search API doesn't support productTypeFrontend can't filter

🟡 HIGH

#IssueImpact
5tires_current without productTypeSearch doesn't distinguish types
6Frontend not updatedCatalog/tires show everything

Fixes

Fix 1: gcp-rebuild-dev-index.sh (5 min)

# WAS:
SYNC_COLLECTIONS="parts_nhl,parts_bns,parts_vnt,parts_kmt,parts_kuh,..."

# SHOULD BE:
SYNC_COLLECTIONS="parts_nhl,parts_bns,parts_vnt,parts_kuh,parts_hot,parts_har,parts_mar,parts_kin,parts_mch"
# WITHOUT parts_kmt!

Fix 2: Apply ES mapping (5 min)

# Add productType to both indices
gcloud compute ssh elasticsearch-vm --zone=us-east1-b --project=noted-bliss-466410-q6 --tunnel-through-iap \
  --command="curl -X PUT 'localhost:9200/parts_current/_mapping' \
    -H 'Content-Type: application/json' \
    -d '{\"properties\":{\"productType\":{\"type\":\"keyword\"}}}'"

gcloud compute ssh elasticsearch-vm --zone=us-east1-b --project=noted-bliss-466410-q6 --tunnel-through-iap \
  --command="curl -X PUT 'localhost:9200/tires_current/_mapping' \
    -H 'Content-Type: application/json' \
    -d '{\"properties\":{\"productType\":{\"type\":\"keyword\"}}}'"

Fix 3: Update data with productType (5 min)

# parts_current → productType='part'
gcloud compute ssh elasticsearch-vm --zone=us-east1-b --project=noted-bliss-466410-q6 --tunnel-through-iap \
  --command="curl -X POST 'localhost:9200/parts_current/_update_by_query?refresh=true' \
    -H 'Content-Type: application/json' \
    -d '{\"script\":{\"source\":\"ctx._source.productType = \\\"part\\\"\"},\"query\":{\"match_all\":{}}}'"

# tires_current → productType='tire'
gcloud compute ssh elasticsearch-vm --zone=us-east1-b --project=noted-bliss-466410-q6 --tunnel-through-iap \
  --command="curl -X POST 'localhost:9200/tires_current/_update_by_query?refresh=true' \
    -H 'Content-Type: application/json' \
    -d '{\"script\":{\"source\":\"ctx._source.productType = \\\"tire\\\"\"},\"query\":{\"match_all\":{}}}'"

Fix 4: Add productType to Search API (15 min)

4.1 schemas/search.ts

export const SearchQuerySchema = z.object({
  // ... existing fields
  productType: z.enum(['part', 'tire', 'accessory']).optional(),
});

4.2 utils/query-builder.ts

// In buildSearchQuery():
if (params.productType) {
  filters.push({ term: { productType: params.productType } });
}

4.3 routes/search.ts

// Add productType to openapi schema and handler

Fix 5: Create tires sync script (5 min)

# gcp-rebuild-tires-index.sh
SYNC_COLLECTIONS="parts_kmt"
SEARCH_INDEX_NAME="tires_current"

Execution Order

  1. Fix 1: Fix gcp-rebuild-dev-index.sh (remove parts_kmt)
  2. Fix 2: Apply ES mapping
  3. Fix 3: Update data (update_by_query)
  4. Fix 4: Add productType to Search API
  5. Test: Verify filtering
  6. Fix 5: Create tires sync script (optional)

Testing After Fixes

# 1. Check mapping
curl -s "localhost:9200/parts_current/_mapping" | jq '.. | .productType? // empty'

# 2. Check data
curl -s "https://api.crop-dev.app/api/search?limit=1" | jq '.parts[0].productType'

# 3. Check filtering
curl -s "https://api.crop-dev.app/api/search?productType=part&limit=1" | jq '.pagination.total'
# Expected: 2594

curl -s "https://api.crop-dev.app/api/search?productType=tire&limit=1" | jq '.pagination.total'
# Expected: 7091 (after adding cross-index search)

Risks

RiskMitigation
update_by_query slow on large data2594 + 7091 = ~10K docs, should be fast
API downtime during deployChanges are backward-compatible
gcp script runs before fixFix it FIRST

On this page