简体   繁体   English

如何在ElasticSearch上自动创建索引?

[英]How to do an automated index creation at ElasticSearch?

How to do an automated index creation at ElasticSearch? 如何在ElasticSearch上自动创建索引?

Just like wordpress? 就像wordpress一样? See: http://gibrown.wordpress.com/2014/02/06/scaling-elasticsearch-part-2-indexing/ 参见: http : //gibrown.wordpress.com/2014/02/06/scaling-elasticsearch-part-2-indexing/

In our case we create one index for every 10 million blogs, with 25 shards per index. 在我们的案例中,我们为每1000万个博客创建一个索引,每个索引有25个分片。

Any light? 有灯吗

Thanks! 谢谢!

You do it in whatever your favorite scripting language is. 您可以使用自己喜欢的脚本语言进行操作。 You first run a query getting a count of the number of documents in the index. 您首先运行查询以获取索引中文档数的计数。 If it's beyond a certain amount you create a new one, either via an Elasticsearch API or a curl. 如果超出一定数量,则可以通过Elasticsearch API或curl创建一个新的数量。

Here's the query to find the number of docs: 这是查找文档数量的查询:

curl --XGET 'http://localhost:9200/youroldindex/_count'

Here's the index creation curl: 这是索引创建curl:

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

You will also probably want to create aliases so that your code can always point to a single index alias and then change the alias as you change your hot index: 您可能还希望创建别名,以便您的代码始终可以指向单个索引别名,然后在更改热索引时更改别名:

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-aliases.html http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-aliases.html

You will probably want to predefine your mappings too: 您可能还需要预定义映射:

curl -XPUT 'http://localhost:9200/yournewindex/yournewmapping/_mapping' -d '
{
    "document" : {
        "properties" : {
            "message" : {"type" : "string", "store" : true }
        }
    }
}
'

Elasticsearch has fairly complete documentation, a few good places to look: 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 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM