🦀 ClawHub
Elasticsearch
by @ivangdavila
Query and index Elasticsearch with proper mappings, analyzers, and search patterns.
TERMINAL
clawhub install elasticsearch📖 About This Skill
name: Elasticsearch description: Query and index Elasticsearch with proper mappings, analyzers, and search patterns. metadata: {"clawdbot":{"emoji":"🔍","requires":{"anyBins":["curl"]},"os":["linux","darwin","win32"]}}
Mapping Mistakes
text for full-text search, keyword for exact match/aggregations—using text for IDs breaks filtersdynamic: "strict" to reject unmapped fields—catches typos in field namesText vs Keyword
text is analyzed (tokenized, lowercased)—"Quick Brown" matches search for "quick"keyword is exact bytes—"Quick Brown" only matches exactly "Quick Brown""title": { "type": "text", "fields": { "raw": { "type": "keyword" }}}title.raw, search on titleQuery vs Filter Context
bool.must for scoring, bool.filter for filtering without scoringAnalyzers
standard analyzer lowercases and removes punctuation—fine for most textkeyword analyzer keeps exact string—use for codes, SKUs, emailsenglish) stem words—"running" matches "run"_analyze endpoint before indexing—surprises in production hurtNested vs Object
{"tags": [{"key":"a","val":1}, {"key":"b","val":2}]} becomes tags.key: [a,b], tags.val: [1,2]key=a AND val=2 incorrectly matches abovenested type to preserve object boundaries—requires nested query wrapperPagination Traps
from + size limited to 10,000 hits—deep pagination failssearch_after for deep pagination—requires consistent sort, typically _idBulk Operations
_bulk API, 5-15MB batchesrefresh=false during bulk loads—refresh after batch completesPerformance
_source: false with stored_fields if you don't need full document—reduces I/Ofilter for cacheable conditions—Elasticsearch caches filter results*term)—forces full scan; use reverse field for suffix searchprofile: true shows query execution breakdown—find slow clausesSharding
Index Management
Aggregations
terms agg needs keyword field—text fields fail or give garbagesize: 10 on terms agg—increase to get all buckets, or use compositenested wrapper—matches nested query patternCommon Errors
_cluster/settingsretry_on_conflict or use optimistic lockingindex.mapping.total_fields.limit and use strict mapping