Why doesn't routing work with ElasticSearch Bulk API?

后端 未结 2 1376
灰色年华
灰色年华 2021-02-10 18:20

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.

Is this a bug i

相关标签:
2条回答
  • 2021-02-10 18:53

    So adding the "routing" parameter to the end of the URL doesn't work.

    I need to add the "_routing" field to the actual document fields to specify which shard it will go to.

    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"} }'
    
    0 讨论(0)
  • @Henley Chiu has given the correct answer, I add one detail:

    • before es 6.1, you can use _routing or routing field for each individual document when bulk
    • after es 6.1(included), you can only use routing

    So, you'd better use routing for better future compatibility.

    0 讨论(0)
提交回复
热议问题