【问题标题】:How to define number of primary and replica shards in elastic search Javascript api?如何在弹性搜索 Javascript api 中定义主分片和副本分片的数量?
【发布时间】:2015-07-03 22:26:12
【问题描述】:

我编写了一些节点脚本来创建和填充弹性搜索中的索引(https://github.com/tgirotto/Elasticsearch);但是,现在我希望能够通过定义主分片和副本分片的数量来自定义索引。我在弹性搜索 javascript api 文档中查找了它,但没有找到任何东西。有什么想法吗?

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    创建索引后无法更改主分片的数量。但是,您可以更改每个主分片的副本数。

    http://www.elastic.co/guide/en/elasticsearch/guide/current/_index_settings.html

    PUT /my_temp_index/_settings
    {
        "number_of_replicas": 1
    }
    

    因此,您必须在创建索引之前仔细确定所需的主分片数量,然后执行以下操作:

    curl -XPUT 'http://localhost:9200/twitter/' -d '{
        "settings" : {
            "number_of_shards" : 3,
            "number_of_replicas" : 2
        }
    }'
    

    编辑:请原谅我的阅读能力……我以为您问的是如何在创建索引后进行更改,而不是如何预先设置分片/副本。

    无论如何,正如您在上面看到的,指定副本/分片的数量相当容易。请查阅 elasticsearch.org 上的明确指南,例如:

    http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html

    【讨论】:

      猜你喜欢
      • 2014-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多