为什么不使用ElasticSearch Bulk API进行路由?

Hen*_*hiu 3 lucene elasticsearch

我正在向ElasticSearch设置批量请求并指定要路由到的分片.

但是当我运行它时,文档会被发送到不同的分片.

这是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"} }'
Run Code Online (Sandbox Code Playgroud)

Hen*_*hiu 10

因此,将"路由"参数添加到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"} }'
Run Code Online (Sandbox Code Playgroud)

  • 只是抬头:您报告的[问题](https://github.com/elasticsearch/elasticsearch/issues/4053)立即修复了[发布](http://www.elasticsearch.org/download /)今天出来的包含修复.感谢您举报,您可能想要更新您的答案.我们也在努力研究文档,您也知道. (3认同)

NiY*_*hun 6

@Henley Chiu 给出了正确答案,我补充一个细节:

  • 在 es 6.1 之前,您可以在批量时为每个单独的文档使用_routingrouting字段
  • 在 es 6.1(included) 之后,你只能使用 routing

所以,routing为了更好的未来兼容性,你最好使用。