rcbo
rcbo

Reputation: 31

How to specify routing using nodejs elasticsearch client?

There doesn't seem to be a way to specify routing value during index operation. I attempted to use 'undocumented params' as mentioned here: https://www.npmjs.org/package/elasticsearch

e.g. client.search( { index: 'abc', type: 'efg', routing: '123' . . . }

I would get 'routing' error since routing is required in the mapping. Is this a bug, missing feature, or am I not setting the correct parameters? Please help

Upvotes: 1

Views: 851

Answers (1)

lrossy
lrossy

Reputation: 533

A little late, but for anyone wondering you can set the routing in the connection path:

var client = new elasticsearch.Client({
  host: 'http://u:pwd@host:port?routing={routing_key}'
});

{ total: 1, successful: 1, failed: 0 }

Also, you can add it as a parameter in the search object:

.search( { index: 'indexname',
  type: 'typename',
  body: { query: { bool: [Object] }, size: 1, aggs: { agg1: [Object] } },
  routing: '2015-03,2015-04' })

Upvotes: 4

Related Questions