Reputation: 7004
I'm having trouble specifying routing on my Elasticsearch bulk update query. I have a mapping that requires routing:
PUT my-index/_mapping
{
"_routing": {
"required": true,
},
"properties": {
"my-property": { "type": "text" }
}
}
I can insert a single document with the query parameter routing fine:
PUT my-index/_doc/my-id?routing=my-routing
{ "id": "my-id", "my-property": "Hi"... }
However, when I bulk update, I'm not sure exactly how to specify the routing field. The documentation says
Each bulk item can include the routing value using the routing field. It automatically follows the behavior of the index / delete operation based on the _routing mapping.
The routing value, is presumably a value on the document body? However, I've tried:
POST my-index/_doc/_bulk
{"index":{"_index": "ch-search-domain", "_type": "_doc", "_id": "my-id" }}
{ "id": "my-id", "routing":"my-routing", "my-property": "Hi" }
However, I get the error:
"status":400,"error":{"type":"routing_missing_exception","reason":"routing is required for [my-index]/[_doc]/[my-id]","index_uuid":"na","index":"my-index"}}}]
Also, while apparently not supported (This answer here says instead to use "routing field for each individual document when bulk" like what I tried above, but I tried the other option for older versions just in case)
POST my-index/_doc/_bulk
{"index":{"_index": "ch-search-domain", "_type": "_doc", "_id": "my-id", "_routing": "my-routing" }}
{ "id": "my-id", "my-property": "Hi"... }
Also fails with:
{"type":"illegal_argument_exception","reason":"Action/metadata line 1 contains an unknown parameter [_routing]"}
I also tried a _routing
field on the document, but it complains that's reserved for routing internally.
Does anyone have an example of how routing is supposed to be specified on bulk indexing operations?
Upvotes: 1
Views: 2246
Reputation: 125488
It should be "routing"
in the bulk operation metadata
POST my-index/_doc/_bulk
{"index":{"_index": "ch-search-domain", "_type": "_doc", "_id": "my-id", "routing": "my-routing" }}
{ "id": "my-id", "my-property": "Hi"... }
Upvotes: 3