我应该在 elasticsearch 的单台机器上使用 sharding/replication 吗?

Should I use sharding/replication on a single machine in elasticsearch?

我在 elasticsearch 的索引中有一个大数据集。我只有一台物理机器,并且在不久的将来不会改变。

如果我不能有更多节点用于 运行 elasticsearch,那么使用分片 and/or 复制有什么意义吗?它仍然会提高性能,还是我应该坚持只有一个分片?

在一台机器上。复制没有意义,因为它主要用于高可用性(如果持有另一个副本的机器出现故障)您仍然可以服务于托管副本的机器的请求,并提供更好的搜索性能,因为您可以从任何副本进行搜索但是在一台机器上,这两个用例都是无效的,因此即使你尝试,ES 也不会在同一节点上分配同一分片的副本。

关于多个主分片,它更复杂,因为它取决于各种因素,如果您有良好的磁盘和 RAM 可用,并且拥有大量数据而不是单个主分片,则意味着更大的段大小和更大的段大小超过 5 GB 就大了,不适合段合并,也难以缓存,另一方面太多的小段也会严重影响搜索性能。你应该知道 ES 每个分片创建一个线程并且有更多的单个索引分片,这意味着在搜索数据时涉及来自同一台机器的更多线程。 最好的是,根据您的数据,您可以进行一些基准测试并选择最适合您的用例的方法。

补充 Opster 所说的。

因此,即使您尝试,ES 集群状态也会变为黄色,因为无法将副本分片分配给主分片所在的同一台机器。 因此,即使您尝试,所有副本分片都会增加 unassigned_shards 计数器

检查集群的状态 curl -XGET "http://localhost:9200/_cluster/health?pretty"

{
  "cluster_name" : "es-test",
  "status" : "yellow",
  "timed_out" : false,
  "number_of_nodes" : 7,
  "number_of_data_nodes" : 7,
  "discovered_master" : true,
  "active_primary_shards" : 8617,
  "active_shards" : 11975,
  "relocating_shards" : 8,
  "initializing_shards" : 0,
  "unassigned_shards" : 46,
  }

"TIP: The number of shards you can hold on a node will be proportional to the amount of heap you have available, but there is no fixed limit enforced by Elasticsearch. A good rule-of-thumb is to ensure you keep the number of shards per node below 20 per GB heap it has configured. A node with a 30GB heap should therefore have a maximum of 600 shards, but the further below this limit you can keep it the better. This will generally help the cluster stay in good health."

https://www.elastic.co/blog/how-many-shards-should-i-have-in-my-elasticsearch-cluster

适用于主分片和副本分片:当你有太多索引,因此分片太多,你开始达到每个节点允许的分片限制。如果您想为新索引修改主分片,也要考虑到这一点。 或者,如果您想重建索引以修改现有索引的主分片设置。