> elasticsearch-search
Configure and use Elasticsearch for full-text search, custom analyzers, aggregations, and index management. Use when a user needs to design search mappings, write complex queries, build aggregation pipelines, tune relevance scoring, or optimize index performance for search workloads.
curl "https://skillshub.wtf/TerminalSkills/skills/elasticsearch-search?format=md"Elasticsearch Search
Overview
Design and implement Elasticsearch search solutions including index mappings, custom analyzers, full-text queries, aggregations, and relevance tuning. Covers index lifecycle, search templates, and performance optimization.
Instructions
Task A: Create Index with Custom Mappings
# Create an index with explicit mappings and custom analyzers
curl -X PUT "http://localhost:9200/products" \
-H "Content-Type: application/json" \
-d '{
"settings": {
"number_of_shards": 3,
"number_of_replicas": 1,
"analysis": {
"analyzer": {
"product_analyzer": {
"type": "custom",
"tokenizer": "standard",
"filter": ["lowercase", "asciifolding", "product_synonyms", "product_stemmer"]
},
"autocomplete_analyzer": {
"type": "custom",
"tokenizer": "autocomplete_tokenizer",
"filter": ["lowercase"]
}
},
"tokenizer": {
"autocomplete_tokenizer": {
"type": "edge_ngram",
"min_gram": 2,
"max_gram": 15,
"token_chars": ["letter", "digit"]
}
},
"filter": {
"product_synonyms": {
"type": "synonym",
"synonyms": ["laptop,notebook", "phone,mobile,cellphone", "tv,television"]
},
"product_stemmer": {
"type": "stemmer",
"language": "english"
}
}
}
},
"mappings": {
"properties": {
"name": {
"type": "text",
"analyzer": "product_analyzer",
"fields": {
"autocomplete": { "type": "text", "analyzer": "autocomplete_analyzer", "search_analyzer": "standard" },
"keyword": { "type": "keyword" }
}
},
"description": { "type": "text", "analyzer": "product_analyzer" },
"category": { "type": "keyword" },
"price": { "type": "float" },
"rating": { "type": "float" },
"tags": { "type": "keyword" },
"created_at": { "type": "date" },
"location": { "type": "geo_point" },
"in_stock": { "type": "boolean" }
}
}
}'
Task B: Full-Text Search Queries
# Multi-match search with boosting
curl -X POST "http://localhost:9200/products/_search" \
-H "Content-Type: application/json" \
-d '{
"query": {
"bool": {
"must": {
"multi_match": {
"query": "wireless noise cancelling headphones",
"fields": ["name^3", "description", "tags^2"],
"type": "best_fields",
"fuzziness": "AUTO"
}
},
"filter": [
{ "term": { "in_stock": true } },
{ "range": { "price": { "gte": 50, "lte": 300 } } }
],
"should": [
{ "range": { "rating": { "gte": 4.0, "boost": 2.0 } } },
{ "term": { "category": { "value": "electronics", "boost": 1.5 } } }
]
}
},
"highlight": {
"fields": {
"name": {},
"description": { "fragment_size": 150, "number_of_fragments": 2 }
}
},
"sort": [
{ "_score": "desc" },
{ "rating": "desc" }
],
"size": 20
}'
# Autocomplete / search-as-you-type query
curl -X POST "http://localhost:9200/products/_search" \
-H "Content-Type: application/json" \
-d '{
"query": {
"bool": {
"must": {
"match": {
"name.autocomplete": { "query": "wire", "operator": "and" }
}
},
"filter": { "term": { "in_stock": true } }
}
},
"size": 10,
"_source": ["name", "category", "price"]
}'
Task C: Aggregations
# Multi-level aggregations for faceted search
curl -X POST "http://localhost:9200/products/_search" \
-H "Content-Type: application/json" \
-d '{
"size": 0,
"query": { "match": { "description": "wireless headphones" } },
"aggs": {
"categories": {
"terms": { "field": "category", "size": 20 },
"aggs": {
"avg_price": { "avg": { "field": "price" } },
"avg_rating": { "avg": { "field": "rating" } }
}
},
"price_ranges": {
"range": {
"field": "price",
"ranges": [
{ "key": "budget", "to": 50 },
{ "key": "mid-range", "from": 50, "to": 150 },
{ "key": "premium", "from": 150, "to": 300 },
{ "key": "luxury", "from": 300 }
]
}
},
"price_stats": { "extended_stats": { "field": "price" } },
"top_rated": {
"top_hits": {
"sort": [{ "rating": "desc" }],
"size": 3,
"_source": ["name", "rating", "price"]
}
}
}
}'
# Date histogram aggregation for time-series analysis
curl -X POST "http://localhost:9200/logs-*/_search" \
-H "Content-Type: application/json" \
-d '{
"size": 0,
"query": { "range": { "@timestamp": { "gte": "now-7d" } } },
"aggs": {
"errors_over_time": {
"date_histogram": {
"field": "@timestamp",
"calendar_interval": "1h"
},
"aggs": {
"error_count": {
"filter": { "term": { "level": "error" } }
},
"error_rate": {
"bucket_script": {
"buckets_path": { "errors": "error_count._count", "total": "_count" },
"script": "params.total > 0 ? (params.errors / params.total) * 100 : 0"
}
}
}
}
}
}'
Task D: Index Lifecycle Management
# Create an ILM policy for log indices
curl -X PUT "http://localhost:9200/_ilm/policy/logs-lifecycle" \
-H "Content-Type: application/json" \
-d '{
"policy": {
"phases": {
"hot": {
"min_age": "0ms",
"actions": {
"rollover": { "max_age": "1d", "max_primary_shard_size": "50gb" },
"set_priority": { "priority": 100 }
}
},
"warm": {
"min_age": "3d",
"actions": {
"shrink": { "number_of_shards": 1 },
"forcemerge": { "max_num_segments": 1 },
"set_priority": { "priority": 50 }
}
},
"cold": {
"min_age": "30d",
"actions": {
"searchable_snapshot": { "snapshot_repository": "backups" },
"set_priority": { "priority": 0 }
}
},
"delete": {
"min_age": "90d",
"actions": { "delete": {} }
}
}
}
}'
Task E: Search Templates
# Create a reusable search template
curl -X PUT "http://localhost:9200/_scripts/product-search" \
-H "Content-Type: application/json" \
-d '{
"script": {
"lang": "mustache",
"source": {
"query": {
"bool": {
"must": { "multi_match": { "query": "{{query}}", "fields": ["name^3", "description"] } },
"filter": [
{{#category}}{ "term": { "category": "{{category}}" } },{{/category}}
{ "term": { "in_stock": true } },
{ "range": { "price": { "gte": "{{min_price}}{{^min_price}}0{{/min_price}}", "lte": "{{max_price}}{{^max_price}}99999{{/max_price}}" } } }
]
}
},
"size": "{{size}}{{^size}}20{{/size}}"
}
}
}'
# Use the search template
curl -X POST "http://localhost:9200/products/_search/template" \
-H "Content-Type: application/json" \
-d '{ "id": "product-search", "params": { "query": "headphones", "category": "electronics", "max_price": 200, "size": 10 } }'
Best Practices
- Use
keywordsub-fields on text fields for exact match filtering and aggregations - Set
fuzziness: "AUTO"for user-facing search to handle typos gracefully - Use
filtercontext for non-scoring clauses (dates, booleans, categories) to leverage caching - Design ILM policies to move data through hot/warm/cold tiers based on access patterns
- Use search templates to keep query logic server-side and simplify client code
- Monitor slow queries with
index.search.slowlog.threshold.query.warn: 2s
> related_skills --same-repo
> zustand
You are an expert in Zustand, the small, fast, and scalable state management library for React. You help developers manage global state without boilerplate using Zustand's hook-based stores, selectors for performance, middleware (persist, devtools, immer), computed values, and async actions — replacing Redux complexity with a simple, un-opinionated API in under 1KB.
> zoho
Integrate and automate Zoho products. Use when a user asks to work with Zoho CRM, Zoho Books, Zoho Desk, Zoho Projects, Zoho Mail, or Zoho Creator, build custom integrations via Zoho APIs, automate workflows with Deluge scripting, sync data between Zoho apps and external systems, manage leads and deals, automate invoicing, build custom Zoho Creator apps, set up webhooks, or manage Zoho organization settings. Covers Zoho CRM, Books, Desk, Projects, Creator, and cross-product integrations.
> zod
You are an expert in Zod, the TypeScript-first schema declaration and validation library. You help developers define schemas that validate data at runtime AND infer TypeScript types at compile time — eliminating the need to write types and validators separately. Used for API input validation, form validation, environment variables, config files, and any data boundary.
> zipkin
Deploy and configure Zipkin for distributed tracing and request flow visualization. Use when a user needs to set up trace collection, instrument Java/Spring or other services with Zipkin, analyze service dependencies, or configure storage backends for trace data.