2013-11-02 17 views
2

我正在將批量請求設置爲ElasticSearch並指定要路由到的分片。爲什麼不使用ElasticSearch Bulk API工作?

但是當我運行它時,文檔被髮送到不同的分片。

這是ElasticSEarch批量中的錯誤嗎?它只適用於索引單個文檔。它在我搜索時起作用。但是,當我做批量導入時不行。

重現:

curl -XPOST 'http://192.168.1.115:9200/_bulk?routing=a' -d ' 
{ "index" : { "_index" : "articles", "_type" : "article", "_id" : "1" } } 
{ "title" : "value1" } 
{ "delete" : { "_index" : "articles", "_type" : "article", "_id" : "2" } } 
{ "create" : { "_index" : "articles", "_type" : "article", "_id" : "3" } } 
{ "title" : "value3" } 
{ "update" : {"_id" : "1", "_type" : "article", "_index" : "index1"} } 
{ "doc" : {"field2" : "value2"} }' 

回答

7

所以添加「路由」參數設置爲URL的末尾不起作用。

我需要將「_routing」字段添加到實際的文檔字段中,以指定它要去哪個分片。

非常不直觀,我希望ElasticSearch記錄下來!有時候我希望我只是選擇了Solr的:*(

希望這有助於其他人在未來

curl -XPOST 'http://192.168.1.115:9200/_bulk?routing=a' -d ' 
{ "index" : { "_index" : "articles", "_type" : "article", "_id" : "1", "_routing" : "b"} } 
{ "title" : "value1" } 
{ "delete" : { "_index" : "articles", "_type" : "article", "_id" : "2", "_routing" : "b" } } 
{ "create" : { "_index" : "articles", "_type" : "article", "_id" : "3", "_routing" : "b" } } 
{ "title" : "value3" } 
{ "update" : {"_id" : "1", "_type" : "article", "_index" : "index1", "_routing" : "b"} } 
{ "doc" : {"field2" : "value2"} }' 
+2

剛擡起頭尋找這樣的:[問題](https://github.com/elasticsearch/elasticsearch/issues/4053)已立即修復,今天發佈的[release](http://www.elasticsearch.org/download/)包含修復程序。感謝您報告它,您可能希望更新你的答案,我們也在努力處理文檔,只是你知道。 – javanna

+0

謝謝javanna。但現在我不能在批量導入時爲每個文檔指定_routing字段??? –

+0

如果內存服務不是這個想法,在網址中的是th默認的一個,當沒有指定每個項目時用作回退。 – javanna