问题描述
我正在向 ElasticSearch 设置批量请求并指定要路由到的分片.
I am setting a Bulk request to ElasticSearch and specifying the shard to route to.
但是当我运行它时,文档会被发送到不同的分片.
But when I run it, the documents get sent to different shards.
这是 ElasticSEarch 批量中的错误吗?当我只索引一个文档时它就可以工作.它在我搜索时有效.但不是在我进行批量导入时.
Is this a bug in ElasticSEarch bulk? it works when I just index a single document. It works when I search. But not when I do a bulk import.
复制:
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"} }'
推荐答案
所以在URL末尾添加routing"参数是行不通的.
So adding the "routing" parameter to the end of the URL doesn't work.
我需要将_routing"字段添加到实际文档字段中,以指定它将转到哪个分片.
I need to add the "_routing" field to the actual document fields to specify which shard it will go to.
非常不直观,我希望 ElasticSearch 能够记录这一点!有时我希望我只选择 Solr :*(
Very unintuitive, and I wish ElasticSearch would've documented this! Sometimes I wish I just chose Solr :*(
希望这可以帮助其他人在未来寻找这个
Hope this helps anyone else looking for this in the future
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"} }'
这篇关于为什么路由不适用于 ElasticSearch Bulk API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!