Elastic Cloud Enterprise to OpenSearch, with search that costs less to run

Search ran on Elastic Cloud Enterprise, with very large shards and no partitioning. We partitioned the data by tenant, fixed the mappings and queries and moved search to two or three smaller OpenSearch clusters per region on Azure.

$1M saved per month
Saved per year
$12M
Change
Elastic Cloud Enterprise to OpenSearch on Azure
Client
Enterprise SaaS company

What we changed

  1. 01Partitioned the data by tenant into smaller indices
  2. 02Brought shards to a sensible size
  3. 03Fixed analyzers and removed nested fields where not needed
  4. 04Rewrote the heaviest queries
  5. 05Two or three OpenSearch clusters per region on Azure, moved without downtime
  6. 06Training for the team: mappings, fixing mistakes, reindex, what to watch

The situation

Search ran on Elastic Cloud Enterprise. The data had grown over the years in a few large indices that were never partitioned, and the shards had become very large.

Large shards are expensive in several ways:

  • a query on a shard runs on one thread, so a large shard means a slow query
  • moving or recovering a large shard takes a long time, so nodes need a lot of headroom
  • the cluster cannot spread the load well, so it has to be sized for the biggest shards, not for the total amount of data

Because of this the client always had to run the largest node sizes available. The cluster was large because of how the data was stored, not because of how much data there was.

What we did

1. Partitioned the data by tenant

We split the large indices by tenant, with index templates and aliases so the application still sees one index. Each tenant's data now lives in its own smaller indices, and old indices can be shrunk, moved to cheaper nodes or deleted.

2. Brought shards to a sensible size

With the data partitioned, each shard is now small enough to query, move and recover quickly, and the load spreads evenly across the nodes. The cluster no longer needs the largest node sizes.

3. Fixed the mappings

  • Analyzers. Each text field got the analyzer that matches how it is searched. Fields that are only filtered on became keyword.
  • nested removed where it was not needed. Every nested object is indexed as a separate hidden document, which multiplies the index size and makes queries on those fields slower.
  • Fields nobody searches are stored but not indexed.

4. Fixed the queries

  • filters instead of scoring queries where relevance does not matter, so results can be cached
  • no leading wildcards
  • search_after instead of deep pagination

5. Built OpenSearch on Azure

The client wanted search on Azure. Instead of one large cluster we built two or three smaller OpenSearch clusters in each region and spread the tenants across them. A problem in one cluster now affects only the tenants on it, and each cluster can be sized and upgraded on its own.

6. Moved without downtime

  • reindexed the data into OpenSearch with the new layout and mappings
  • wrote to both clusters during the move and compared results
  • switched reads to OpenSearch, then turned Elastic Cloud Enterprise off

7. Worked with the team

Most of the problems started with decisions that looked fine when the data was small. We wanted the team to make the right ones on their own from now on, so we ran sessions with the developers:

  • How to design a mapping. Choosing field types and analyzers, when nested is really needed and when it is not, what to index and what only to store.
  • What to do when a mapping is wrong. A field mapping cannot be changed in place. You create a new index with the right mapping, reindex into it and switch the alias. We showed this step by step.
  • How to use reindex safely. Running it in slices, throttling it so it does not slow down search, and checking the document counts before switching.
  • What to watch. Shard size, heap usage, the slow log and the number of shards per node, and when each of them means it is time to act.

Result

$1M a month saved. Most of it came from the new data layout, smaller shards and lighter queries, which allowed much smaller nodes.