Elasticsearch 中的索引别名和通配符索引端点是否完全相同?

Are index aliases and wildcard index endpoints in Elasticsearch exactly the same thing?

Index Aliases 的 Elasticsearch 文档说:

The index aliases API allow to alias an index with a name, with all APIs automatically converting the alias name to the actual index name. An alias can also be mapped to more than one index, and when specifying it, the alias will automatically expand to the aliases indices.

Multiple Indices 的文档说:

Most APIs that refer to an index parameter support execution across multiple indices, using simple test1,test2,test3 notation (or _all for all indices). It also support wildcards, for example: test*, and the ability to "add" (+) and "remove" (-), for example: +test*,-test3.

场景 #1

  1. 您有 2014 年的 12 个月度指数,每个指数都以日期模式命名,例如someprefix_2014-07

  2. 您将所有这些索引映射到名为 2014 的别名。

  3. 这两个请求都会 return 相同的结果:

    • $ curl -XGET http://localhost:9200/someprefix_2014-*/_stats

    • $ curl -XGET http://localhost:9200/2014/_stats

场景 #2

  1. 您的集群中总共有 24 个月度索引,您决定将所有这些索引作为目标。

  2. 所有这些请求都会return相同的结果:

    • $ curl -XGET http://localhost:9200/_stats

    • $ curl -XGET http://localhost:9200/_all/_stats

    • $ curl -XGET http://localhost:9200/*/_stats

    • $ curl -XGET http://localhost:9200/someprefix_*/_stats

我的问题

所有这些方法都在做同样的事情吗"under the hood",或者是否有一种方法的性能比其他方法更好?

我问是因为我读到 Wildcard Queries 是一个常见的性能瓶颈,但我从未见过任何类似的关于在索引端点中使用别名或通配符的警告 - 或区分默认别名(如 _all) 来自定制的。

从代码执行的角度来看,它们完全不同。但它们在功能上是相同的,并且具有相同的性能配置文件。

别名实际上只是附加到现有索引的 "tags"。因此,当您针对 2014 别名进行搜索时,Elasticsearch 只会扫描集群状态中的索引列表,并找到所有标记有该别名的索引。

当您搜索通配符索引模式时,它会扫描索引列表以查看哪些名称与正则表达式匹配。

所以性能基本上是一样的,因为实际的搜索完全不受影响:无论如何都会查询与这些搜索关联的分片,并且所有索引到分片的查找都将在协调节点上发生很快,不管用什么方法。

所以别担心,您可以选择对您更有意义的一个:)

PS。不鼓励使用通配符查询,因为它们 do 会影响性能。他们必须生成并检查大量潜在的令牌,这会对延迟产生不可忽视的影响。但它们与索引通配符或 ES 周围的许多其他通配符有很大不同。在 ES 中支持模式匹配/通配符的大多数东西只是 Java 正则表达式,而 wildcard 查询是 Lucene 内部针对倒排索引的花式自动机魔法......非常不同:)