在索引编制期间,Elasticsearch有时不会响应

时间:2017-02-27 16:05:59

标签: elasticsearch

我想在Elasticsearch中索引一个包含100万行的MySQL表。我通过PHP使用foreach循环尝试这个。但过了一段时间Elasticsearch没有响应,而且这个过程正在堵塞。我尝试了一些配置,但它没有用。我认为ElasticSearch无法达到PHP的速度。有没有人以前遇到过这个问题?我该如何解决这个问题?

我的弹性搜索配置;

bootstrap.mlockall: true
indices.fielddata.cache.size:  40%
http.max_content_length: 1024mb
indices.recovery.max_bytes_per_sec: 1024mb
indices.memory.index_buffer_size: 50%
min_index_buffer_size: 512mb
max_index_buffer_size: 24gb
indices.memory.min_shard_index_buffer_size: 512mb
indices.recovery.concurrent_streams: 30
indices.recovery.file_chunk_size: 256mb
indices.recovery.translog_ops: 10000
indices.recovery.translog_size: 256mb
indices.recovery.compress: true
indices.recovery.max_bytes_per_sec: 1gb

1 个答案:

答案 0 :(得分:0)

刷新间隔无效

  

刷新API允许显式刷新一个或多个索引,使自上次刷新以来执行的所有操作都可用于搜索。 (近)实时功能取决于所使用的索引引擎。例如,内部调用需要刷新,但默认情况下会定期调度刷新。

有弹性搜索的refresh_interval配置。此功能可以协调您的刷新操作。您可以将此间隔设置为-1,以便在索引大型数据集时使其无效。

curl -XPUT localhost:9200/test/_settings -d '{
    "index" : {
        "refresh_interval" : "-1"
    } }'

通过此更改,您的批量索引将更快。在这种情况下,现在您应该手动刷新索引。索引数据后,需要重新更改配置。

curl -XPUT localhost:9200/test/_settings -d '{
    "index" : {
        "refresh_interval" : "1s"
    } }'

你以前试过吗?

批量索引

如果您可以同时索引多个数据,则可以使用批量API。您可以通过批量操作获得一些性能。因为你会去api而不是很多次。这将大大提高索引速度。您可以在下面找到有关批量索引的示例请求:

POST _bulk
{ "index" : { "_index" : "test", "_type" : "type1", "_id" : "1" } }
{ "field1" : "value1" }
{ "delete" : { "_index" : "test", "_type" : "type1", "_id" : "2" } }
{ "create" : { "_index" : "test", "_type" : "type1", "_id" : "3" } }
{ "field1" : "value3" }
{ "update" : {"_id" : "1", "_type" : "type1", "_index" : "test"} }
{ "doc" : {"field2" : "value2"} }

存储

Elasticsearch大量使用磁盘,因此存储非常重要。因为如果不使用SSD,它可能会成为你的瓶颈。

有关详细信息,请查看the indexing performance tips文章。它真的会帮助你。