Elasticsearch

From G1Joshi/Agent-Skills · View interactive version

Elasticsearch is an AI agent skill from the GitHub repository G1Joshi/Agent-Skills. Expert Elasticsearch assistance covering full-text search, inverted indexes, mappings, aggregations, and cluster lifecycle. Use when building search engines, analyzing logs (ELK), or implementing autocomplete search.

How to use this skill

Skill file

Elasticsearch

Elasticsearch is a distributed search and analytics engine built on Apache Lucene. It is the heart of the ELK Stack (Elastic, Logstash, Kibana) and a leading Vector Database for AI.

When to Use

Quick Start

# REST API - Search for "bike"
GET /products/_search
{
  "query": {
    "match": {
      "description": "bike"
    }
  }
}

Core Concepts

Inverted Index & Tokenization Pipeline

Analyzers split text into tokens, normalize casing, apply stemming, and build inverted term-to-document indexes:

"The quick brown fox" ──Analyzer──→ ['quick', 'brown', 'fox']
Inverted Index:
  'brown' -> [Doc 1, Doc 4]
  'fox'   -> [Doc 1, Doc 2]

Query DSL (Bool, Match, Multi-Match)

Constructs rich boolean relevancy queries:

POST /products/_search
{
  "query": {
    "bool": {
      "must": [
        { "multi_match": { "query": "wireless noise cancelling", "fields": ["title^3", "description"] } }
      ],
      "filter": [
        { "term": { "in_stock": true } },
        { "range": { "price": { "lte": 350.00 } } }
      ]
    }
  },
  "aggs": {
    "popular_brands": { "terms": { "field": "brand.keyword", "size": 5 } }
  }
}

Index Lifecycle Management (ILM) & Hot-Warm-Cold Tiers

Automates moving aging indices across storage tiers to reduce infrastructure costs:

[ Hot Tier (Fast NVMe SSDs) ] ──30 Days──→ [ Warm Tier (Standard SSD) ] ──90 Days──→ [ Cold Tier / S3 Snapshot ]

Common Patterns

Multi-Match Search with Field Boosting and Fuzziness

Problem: Search queries fail to return relevant results due to minor typos or lack of ranking priority.

Solution:

Use multi_match queries with fuzziness and title field boosting (^3):

POST /products/_search
{
  "query": {
    "multi_match": {
      "query": "wirless headphone",
      "fields": ["title^3", "brand^2", "description"],
      "fuzziness": "AUTO",
      "prefix_length": 2
    }
  },
  "aggs": {
    "categories": {
      "terms": { "field": "category.keyword" }
    }
  }
}

Best Practices

Do:

Don't:

Troubleshooting

| Error | Cause | Solution |

| :---------------------------------------------------- | :----------------------------------------------------------------------------- | :--------------------------------------------------------------------------- |

| circuit_breaking_exception: [parent] Data too large | JVM heap exhaustion during large aggregation or unbounded wildcard query. | Increase cluster heap, reduce aggregation bucket sizes, or scale data nodes. |

| Cluster status is RED | Primary shards unassigned due to node failure or storage exhaustion. | Check shard allocation explain API: GET /_cluster/allocation/explain. |

| Fielddata is disabled on text fields | Attempting to aggregate or sort on a text field without keyword sub-field. | Update query to target fieldname.keyword. |

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.