[英]How to do an automated index creation at ElasticSearch?
如何在ElasticSearch上自动创建索引?
就像wordpress一样? 参见: http : //gibrown.wordpress.com/2014/02/06/scaling-elasticsearch-part-2-indexing/
在我们的案例中,我们为每1000万个博客创建一个索引,每个索引有25个分片。
有灯吗
谢谢!
您可以使用自己喜欢的脚本语言进行操作。 您首先运行查询以获取索引中文档数的计数。 如果超出一定数量,则可以通过Elasticsearch API或curl创建一个新的数量。
这是查找文档数量的查询:
curl --XGET 'http://localhost:9200/youroldindex/_count'
这是索引创建curl:
curl -XPUT 'http://localhost:9200/yournewindex/' -d '{
"settings" : {
"number_of_shards" : 25,
"number_of_replicas" : 2
}
}'
您可能还希望创建别名,以便您的代码始终可以指向单个索引别名,然后在更改热索引时更改别名:
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-aliases.html
您可能还需要预定义映射:
curl -XPUT 'http://localhost:9200/yournewindex/yournewmapping/_mapping' -d '
{
"document" : {
"properties" : {
"message" : {"type" : "string", "store" : true }
}
}
}
'
Elasticsearch有相当完整的文档,有几个不错的地方:
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping.html http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-create-index.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.