0Pricing
Elasticsearch & Full Text Search Systems · Lesson

Indexing Performance Best Practices

Implement best practices for indexing data, such as bulk indexing, refresh intervals, and segment merging, to improve ingestion speed.

Indexing Performance Best Practices is a free Elasticsearch & Full Text Search Systems lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Elasticsearch & Full Text Search Systems learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Boosting Indexing Speed

Why is indexing performance crucial? It's about efficiently adding data to Elasticsearch. Fast indexing means your data is searchable sooner and your cluster resources are used effectively.

This lesson will show you how to speed things up!

How Indexing Works

When you index a document, Elasticsearch doesn't just store it. It goes through a process:

  • Analysis: Text fields are broken down into terms.
  • Storage: Document is added to Lucene segments.
  • Refresh: Segments are made searchable.
  • Flush: Segments are written to disk.

Each step has performance implications.

Single Docs: A Performance Bottleneck

Indexing documents one by one means a separate network request and processing overhead for each. Imagine sending thousands of individual letters instead of one large package.

This approach is fine for occasional updates, but for large datasets, it's very inefficient and slow.

Speed Up with Bulk Indexing

Bulk indexing allows you to send multiple index, update, or delete operations in a single API request.

This drastically reduces network round trips and overhead, making data ingestion much faster. It's the go-to method for loading large amounts of data.

Your First Bulk Request

The bulk API uses a special format: action_and_metadata followed by the document_body. Each pair must be on its own line.

Try indexing two documents in one go:

POST /_bulk
{"index": {"_index": "products", "_id": "1"}}
{"name": "Laptop Pro X", "price": 1200}
{"index": {"_index": "products", "_id": "2"}}
{"name": "Wireless Mouse", "price": 25}

Refresh Intervals: Searchability vs. Speed

When a document is indexed, it's not immediately searchable. Elasticsearch periodically "refreshes" an index, making newly indexed documents visible for search.

  • Frequent refreshes: Documents become searchable faster, but consume more resources (CPU, I/O).
  • Less frequent refreshes: Slower searchability, but better indexing performance.

The default refresh interval is 1 second.

Optimize Refresh for Bulk Loads

For large bulk indexing operations, you can temporarily disable refreshes or increase the interval. Remember to set it back afterwards!

Disable refreshes:

PUT /my_index/_settings
{
  "index": {
    "refresh_interval": "-1"
  }
}

Lucene Segments & Merging

Elasticsearch stores data in Lucene segments. Each refresh creates new segments. Too many small segments can degrade query performance.

Elasticsearch automatically merges smaller segments into larger ones in the background. This process is resource-intensive but crucial for query speed.

When to Force Merge

For indices that are no longer being written to (read-only), you can explicitly trigger a force merge to consolidate segments into a single segment (or a few larger ones).

This can significantly improve search performance, but it's a heavy operation and should only be done on static indices.

POST /my_static_index/_forcemerge?max_num_segments=1

Indexing Best Practices Check

You're about to ingest 1 million new documents into an Elasticsearch index. Which of the following strategies would best improve the indexing speed?

Recap: Faster Indexing

Great job! You've learned key strategies to optimize Elasticsearch indexing performance:

  • Use the Bulk API for large data loads.
  • Adjust refresh intervals (e.g., disable/increase) during bulk indexing.
  • Understand segment merging and consider _forcemerge for static indices.

These practices ensure your data is ingested quickly and efficiently!

Frequently asked questions

Is the “Indexing Performance Best Practices” lesson free?

Yes — the full text of “Indexing Performance Best Practices” is free to read here on the web, and the Elasticsearch & Full Text Search Systems course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Elasticsearch & Full Text Search Systems course, upgrade to CoddyKit PRO.

What will I learn in “Indexing Performance Best Practices”?

Implement best practices for indexing data, such as bulk indexing, refresh intervals, and segment merging, to improve ingestion speed. You practise Elasticsearch & Full Text Search Systems with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Elasticsearch & Full Text Search Systems?

No prior experience is required. Elasticsearch & Full Text Search Systems on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Indexing Performance Best Practices” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Elasticsearch & Full Text Search Systems lesson?

Yes. Every Elasticsearch & Full Text Search Systems lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Query Optimization Strategies
  2. Indexing Performance Best Practices
  3. Caching and Concurrency
  4. Profiling and Slow Query Logs
← Back to Elasticsearch & Full Text Search Systems