Skip to content
Tutorials Center
My learning

Topics

Lesson 18 of 43 ยท Searching

Searching Many Indices: Wildcards, Aliases and Cross-Index Queries

Search several Elasticsearch indices in one request: wildcard patterns, aliases and filtered aliases, the _index field, boosting per index and why scores differ between indices.

So far every request searched one index. Real systems rarely stay that way. Logs go into one index per day, a shop keeps products-v1 and products-v2 during a migration, and a global search box looks through articles, products and help pages at once. Elasticsearch handles all of this in one request, because the target part of the URL can name many indices.

This lesson covers the ways to name several indices, how aliases make that safe, and one trap: relevance scores from different indices are not always comparable. The cluster cannot run on this site, so the requests are read-only and the runnable examples are JavaScript stand-ins.

Naming several indices

All of these are valid targets for _search, _count and many other APIs:

HTTP
GET /products-v1,products-v2/_search
GET /logs-2026.11.*/_search
GET /logs-*,-logs-2026.11.01/_search
GET /_search
GET /_all/_search
  • A comma-separated list searches exactly those indices.
  • A wildcard such as logs-2026.11.* matches every index whose name fits. New indices that appear later are included automatically.
  • A leading - excludes a name or pattern from what came before it.
  • No target, or _all, means every index. That is almost never what you want in production, and some clusters forbid it.

If a name does not exist, the request fails with a 404. Add ignore_unavailable=true to skip missing or closed indices, and allow_no_indices=true to accept a wildcard that matches nothing. Wildcards also skip hidden indices (names starting with a dot) unless you set expand_wildcards=all.

Every shard of every matched index takes part in the search, so a wildcard over 365 daily indices with 5 shards each touches 1,825 shards. See Query Performance and Shards, Replicas and Clusters for why shard count matters.

Aliases

An alias is a second name for one or more indices. You search products, and the cluster decides which real indices that means:

HTTP
POST /_aliases
{
  "actions": [
    { "add":    { "index": "products-v2", "alias": "products" } },
    { "remove": { "index": "products-v1", "alias": "products" } }
  ]
}

The actions in one request are applied atomically, so searches never see a half-switched state. This is how you reindex without downtime: build products-v2, then flip the alias (see Using Elasticsearch from Code).

An alias can point to many indices, which makes it a named group:

HTTP
POST /_aliases
{
  "actions": [
    { "add": { "indices": ["logs-2026.11.01", "logs-2026.11.02"], "alias": "logs-recent" } }
  ]
}

Filtered aliases and routing

An alias can carry a filter. Searches through it only see matching documents, which is a cheap way to give each tenant or team a "view":

HTTP
POST /_aliases
{
  "actions": [
    {
      "add": {
        "index": "orders",
        "alias": "orders-acme",
        "filter": { "term": { "customer_id": "acme" } },
        "routing": "acme"
      }
    }
  ]
}

With routing, the alias also sends requests only to the shard where that tenant's documents live. A filtered alias is a convenience and a performance helper, but not a security boundary on its own: anyone who can search the underlying index sees everything. Combine it with a role that only grants access to the alias (see Security, Backups and Operations).

When an alias points to several indices, you can write to it only if exactly one of them is marked "is_write_index": true. That pattern is the basis of rollover for time-based data.

Which index did a hit come from?

Each hit shows its _index. You can also query it, since the index name is a built-in field:

HTTP
GET /articles,products,help-pages/_search
{
  "query": {
    "bool": {
      "must":   { "match": { "title": "wireless charger" } },
      "filter": { "terms": { "_index": ["products", "articles"] } }
    }
  }
}

This restricts the search inside one request, even when the URL names more. Aggregating on _index gives you a facet "results per source": { "terms": { "field": "_index" } }.

Boosting one index over another

A global search box usually wants products to outrank help pages. Use indices_boost at the top level of the request:

HTTP
GET /articles,products,help-pages/_search
{
  "indices_boost": [
    { "products": 2.0 },
    { "help-pages": 0.5 }
  ],
  "query": { "match": { "title": "wireless charger" } }
}

You can do the same inside bool with should clauses on _index. Both approaches tilt the score. They do not guarantee an order.

Scores across indices: the caveat

BM25 relevance uses statistics: how many documents contain a term and how long fields are on average (see Relevance and BM25). Those statistics are computed per shard by default. A term that is rare in articles may be common in products, so the same word gets a different weight in each index, and the scores of hits from different indices do not sit on one fair scale.

Two ways to cope:

  • Use search_type=dfs_query_then_fetch. A first phase collects global term statistics from all shards, and the second phase scores with them. Scores become comparable, at the cost of an extra round trip.
  • Use indices_boost or per-index should clauses to correct the result by hand, and test with real queries.

If the indices have different fields, remember that a field missing from an index simply matches nothing there. Query a field that exists in only one of them and the other index contributes no hits.

Stand-ins you can run

The first stand-in resolves index expressions the way the cluster does: lists, wildcards, exclusions and the missing-index error. It models only name matching, not permissions or closed indices.

JS Resolving index expressions

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The second stand-in shows the score caveat. Two tiny "indices" weigh the word "charger" with their own statistics, then with shared statistics. The formula is a simplified IDF, not the full BM25.

JS Why scores differ between indices

Press Run (or Ctrl + Enter) to see the console output here.

No output.

With per-index statistics, "charger" looks rarer and more important in one index than in the other, even though both mean the same thing to a shopper. The shared weight is the same for both, and the boost is then your explicit decision.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does the target logs-*,-logs-2026.11.01 search?

    A pattern selects indices and a later name with a leading minus removes matches from the selection.
  2. 2. Why is a filtered alias not enough to keep tenants apart?

    The filter is applied only when searching through the alias. Permissions must restrict users to the alias itself.
  3. 3. Why can scores from two indices be unfair to compare?

    BM25 depends on term frequency statistics, and different data sets give different statistics. dfs_query_then_fetch or boosts help.
  4. 4. Which request switches an alias from one index to another without a gap?

    Actions in one _aliases call are applied atomically, so searches see either the old or the new state.

Summary

  • A search target can be a comma-separated list, a wildcard, or an exclusion with a leading -. Avoid _all in production.
  • Aliases give indices a stable name and let you switch atomically; filtered aliases and routing give cheap views, but are not security by themselves.
  • Every hit has an _index; you can filter and aggregate on it and use indices_boost to favour one source.
  • Scores from different indices use different statistics. Use dfs_query_then_fetch or explicit boosts when mixing them.

Next: find documents that resemble a given one in More Like This and Similarity Queries.