我之前使用elasticsearch-scrolltoend作为插件,在升级到5.0之后,这个插件似乎不能工作。如何使用elasticsearch 5.0扫描和滚动大型数据集?
在尝试使用elasticsearch-js docs中的实现时,我也收到一个错误
json { "error": { "root_cause": [ { "type": "illegal_argument_exception", "reason": "Failed to parse request body" } ], "type": "illegal_argument_exception", "reason": "Failed to parse request body", "caused_by": { "type": "json_parse_exception", "reason": "Unrecognized token 'DnF1ZXJ5VGhlbkZldGNoBQAAAAAAAAHKFnV6a2NabEh4VDZLQmdzUzY0Y2tpd0EAAAAAAAAByxZ1emtjWmxIeFQ2S0Jnc1M2NGNraXdBAAAAAAAAAcwWdXprY1psSHhUNktCZ3NTNjRja2l3QQAAAAAAAAHOFnV6a2NabEh4VDZLQmdzUzY0Y2tpd0EAAAAAAAABzRZ1emtjWmxIeFQ2S0Jnc1M2NGNraXdB': was expecting ('true', 'false' or 'null')\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@67ba4d99; line: 1, column: 457]" } }, "status": 400 }
发布于 2017-04-19 01:49:22
无法识别的令牌响应错误是在13.0.0-rc1中修复的错误--请参阅this issue for reference
至于实现,heres how I did it without the elasticsearch-scrolltoend plugin
// methods in some ES6 class
...
fetchStuff(min, max = min) {
const body = new Bodybuilder();
body.size(3);
body.filter('range', 'timestamp', {
gte: min,
lte: max
});
return this.elasticsearch.search({
index: 'my-alias',
type: 'my-doc',
body: body.build('v2'), // have not upgraded to newer bodybuilder package yet
scroll: '15s'
})
.then((res) => this._scrollToEnd(res, []))
.then((events) => {
// sort by timestamp then _id
events = _.sortBy(events, ['_.source.timestamp', '_id']);
return events;
});
}
_scrollToEnd(res, events) {
return Promise.resolve().then(() => {
events = events.concat(_.get(res, 'hits.hits', []));
if (res.hits.total > events.length) {
return this.elasticsearch.scroll({
scrollId: res._scroll_id,
scroll: '15s'
})
.then((res) => this._scrollToEnd(res, events));
}
return events;
});
}https://stackoverflow.com/questions/43479007
复制相似问题