簡體   English   中英

如何在ElasticSearch上自動創建索引?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM