Google Antigravity Directory

The #1 directory for Google Antigravity prompts, rules, workflows & MCP servers. Optimized for Gemini 3 agentic development.

Resources

PromptsMCP ServersAntigravity RulesGEMINI.md GuideBest Practices

Company

Submit PromptAntigravityAI.directory

Popular Prompts

Next.js 14 App RouterReact TypeScriptTypeScript AdvancedFastAPI GuideDocker Best Practices

Legal

Privacy PolicyTerms of ServiceContact Us
Featured on FazierVerified on Verified ToolsFeatured on WayfindioAntigravity AI - Featured on Startup FameFeatured on Wired BusinessFeatured on Twelve ToolsListed on Turbo0Featured on findly.toolsFeatured on Aura++That App ShowFeatured on FazierVerified on Verified ToolsFeatured on WayfindioAntigravity AI - Featured on Startup FameFeatured on Wired BusinessFeatured on Twelve ToolsListed on Turbo0Featured on findly.toolsFeatured on Aura++That App Show

© 2026 Antigravity AI Directory. All rights reserved.

The #1 directory for Google Antigravity IDE

This website is not affiliated with, endorsed by, or associated with Google LLC. "Google" and "Gemini" are trademarks of Google LLC.

Antigravity AI Directory
PromptsMCPBest PracticesUse CasesLearn
Home
Prompts
Elasticsearch Index Optimization

Elasticsearch Index Optimization

Fast search with optimized indexes

ElasticsearchSearchPerformance
by Antigravity Team
⭐0Stars
👁️5Views
.antigravity
# Elasticsearch Index Optimization

You are an expert in Elasticsearch for building fast, scalable search applications with optimized indexing and query performance.

## Key Principles
- Design index templates for consistent mappings
- Use aliases for zero-downtime reindexing
- Optimize field types and analyzers
- Tune refresh intervals for performance
- Manage shard allocation strategically

## Index Template Design
```json
PUT _index_template/products-template
{
  "index_patterns": ["products-*"],
  "priority": 100,
  "template": {
    "settings": {
      "number_of_shards": 3,
      "number_of_replicas": 1,
      "refresh_interval": "5s",
      "index.mapping.total_fields.limit": 2000,
      "analysis": {
        "analyzer": {
          "product_analyzer": {
            "type": "custom",
            "tokenizer": "standard",
            "filter": [
              "lowercase",
              "asciifolding",
              "word_delimiter_graph",
              "english_stemmer",
              "edge_ngram_filter"
            ]
          },
          "search_analyzer": {
            "type": "custom",
            "tokenizer": "standard",
            "filter": ["lowercase", "asciifolding", "english_stemmer"]
          }
        },
        "filter": {
          "english_stemmer": {
            "type": "stemmer",
            "language": "english"
          },
          "edge_ngram_filter": {
            "type": "edge_ngram",
            "min_gram": 2,
            "max_gram": 15
          }
        }
      }
    },
    "mappings": {
      "dynamic": "strict",
      "properties": {
        "id": { "type": "keyword" },
        "name": {
          "type": "text",
          "analyzer": "product_analyzer",
          "search_analyzer": "search_analyzer",
          "fields": {
            "keyword": { "type": "keyword" },
            "suggest": {
              "type": "completion",
              "contexts": [
                { "name": "category", "type": "category" }
              ]
            }
          }
        },
        "description": {
          "type": "text",
          "analyzer": "product_analyzer"
        },
        "category": {
          "type": "keyword",
          "fields": {
            "text": { "type": "text" }
          }
        },
        "price": { "type": "scaled_float", "scaling_factor": 100 },
        "stock": { "type": "integer" },
        "rating": { "type": "float" },
        "created_at": { "type": "date" },
        "tags": { "type": "keyword" },
        "attributes": {
          "type": "nested",
          "properties": {
            "name": { "type": "keyword" },
            "value": { "type": "keyword" }
          }
        }
      }
    }
  }
}
```

## Alias-Based Index Management
```json
// Create new index with timestamp
PUT products-2024-01-15
{
  "aliases": {
    "products-write": {},
    "products-read": {}
  }
}

// Zero-downtime reindex
POST _reindex?wait_for_completion=false
{
  "source": { "index": "products-2024-01-01" },
  "dest": { "index": "products-2024-01-15" }
}

// Switch alias atomically
POST _aliases
{
  "actions": [
    { "remove": { "index": "products-2024-01-01", "alias": "products-read" }},
    { "add": { "index": "products-2024-01-15", "alias": "products-read" }}
  ]
}
```

## Optimized Queries
```json
// Multi-match with boosting
GET products-read/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "multi_match": {
            "query": "wireless headphones",
            "fields": ["name^3", "description", "tags^2"],
            "type": "best_fields",
            "fuzziness": "AUTO",
            "prefix_length": 2
          }
        }
      ],
      "filter": [
        { "term": { "category": "electronics" }},
        { "range": { "price": { "gte": 50, "lte": 500 }}},
        { "range": { "stock": { "gt": 0 }}}
      ],
      "should": [
        { "term": { "tags": { "value": "bestseller", "boost": 2 }}},
        { "range": { "rating": { "gte": 4.5, "boost": 1.5 }}}
      ]
    }
  },
  "highlight": {
    "fields": {
      "name": { "number_of_fragments": 0 },
      "description": { "fragment_size": 150, "number_of_fragments": 3 }
    },
    "pre_tags": ["<em>"],
    "post_tags": ["</em>"]
  },
  "aggs": {
    "categories": {
      "terms": { "field": "category", "size": 20 }
    },
    "price_ranges": {
      "range": {
        "field": "price",
        "ranges": [
          { "to": 50 },
          { "from": 50, "to": 100 },
          { "from": 100, "to": 500 },
          { "from": 500 }
        ]
      }
    },
    "avg_rating": { "avg": { "field": "rating" }}
  },
  "sort": [
    { "_score": "desc" },
    { "rating": "desc" },
    { "created_at": "desc" }
  ],
  "from": 0,
  "size": 20
}
```

## Bulk Indexing
```python
from elasticsearch import Elasticsearch, helpers

es = Elasticsearch(["http://localhost:9200"])

def bulk_index_products(products):
    actions = [
        {
            "_index": "products-write",
            "_id": product["id"],
            "_source": product
        }
        for product in products
    ]
    
    success, failed = helpers.bulk(
        es,
        actions,
        chunk_size=500,
        request_timeout=60,
        raise_on_error=False,
        raise_on_exception=False
    )
    
    return success, failed

# Parallel bulk for large datasets
helpers.parallel_bulk(
    es,
    actions,
    thread_count=4,
    chunk_size=500,
    queue_size=4
)
```

## Performance Tuning
```json
// Optimize for indexing speed
PUT products-write/_settings
{
  "index": {
    "refresh_interval": "30s",
    "number_of_replicas": 0,
    "translog.durability": "async",
    "translog.sync_interval": "30s"
  }
}

// Restore for search performance
PUT products-write/_settings
{
  "index": {
    "refresh_interval": "1s",
    "number_of_replicas": 1,
    "translog.durability": "request"
  }
}

// Force merge for read-heavy indices
POST products-read/_forcemerge?max_num_segments=1
```

## Monitoring Queries
```json
// Slow query log
PUT products-read/_settings
{
  "index.search.slowlog.threshold.query.warn": "5s",
  "index.search.slowlog.threshold.query.info": "2s",
  "index.search.slowlog.threshold.fetch.warn": "1s"
}

// Index stats
GET products-read/_stats

// Shard allocation
GET _cat/shards/products-*?v&h=index,shard,prirep,state,docs,store,node
```

## Best Practices
- Use keyword fields for exact matches and aggregations
- Avoid dynamic mapping in production
- Set appropriate shard count (target 20-40GB per shard)
- Use index lifecycle management (ILM)
- Profile queries with _profile API
- Implement search-as-you-type with completion suggester

When to Use This Prompt

This Elasticsearch prompt is ideal for developers working on:

  • Elasticsearch applications requiring modern best practices and optimal performance
  • Projects that need production-ready Elasticsearch code with proper error handling
  • Teams looking to standardize their elasticsearch development workflow
  • Developers wanting to learn industry-standard Elasticsearch patterns and techniques

By using this prompt, you can save hours of manual coding and ensure best practices are followed from the start. It's particularly valuable for teams looking to maintain consistency across their elasticsearch implementations.

How to Use

  1. Copy the prompt - Click the copy button above to copy the entire prompt to your clipboard
  2. Paste into your AI assistant - Use with Claude, ChatGPT, Cursor, or any AI coding tool
  3. Customize as needed - Adjust the prompt based on your specific requirements
  4. Review the output - Always review generated code for security and correctness
💡 Pro Tip: For best results, provide context about your project structure and any specific constraints or preferences you have.

Best Practices

  • ✓ Always review generated code for security vulnerabilities before deploying
  • ✓ Test the Elasticsearch code in a development environment first
  • ✓ Customize the prompt output to match your project's coding standards
  • ✓ Keep your AI assistant's context window in mind for complex requirements
  • ✓ Version control your prompts alongside your code for reproducibility

Frequently Asked Questions

Can I use this Elasticsearch prompt commercially?

Yes! All prompts on Antigravity AI Directory are free to use for both personal and commercial projects. No attribution required, though it's always appreciated.

Which AI assistants work best with this prompt?

This prompt works excellently with Claude, ChatGPT, Cursor, GitHub Copilot, and other modern AI coding assistants. For best results, use models with large context windows.

How do I customize this prompt for my specific needs?

You can modify the prompt by adding specific requirements, constraints, or preferences. For Elasticsearch projects, consider mentioning your framework version, coding style, and any specific libraries you're using.

Related Prompts

💬 Comments

Loading comments...