我正在尝试使用npm包elasticsearch创建索引,并且一直在收到以下错误。
'找不到uri [/ myindex]和方法[POST]'
的处理程序 esClient.indices.create({
index: 'myindex'
}, function(err, resp, status) {
cb(err, resp);
});
以下代码适用于Elasticsearch 2.3
这是tracelog
Elasticsearch DEBUG: 2017-04-03T13:54:24Z
starting request { method: 'POST', path: '/myindex1', query: {} }
Elasticsearch TRACE: 2017-04-03T13:54:24Z
-> POST http://localhost:9200/myindex1
<- 400
No handler found for uri [/myindex1] and method [POST]
Elasticsearch DEBUG: 2017-04-03T13:54:24Z
Request complete
{ Error: Bad Request
at respond (/Users/Ut/Fitternity/metropolis/node_modules/elasticsearch/src/lib/transport.js:293:15)
at checkRespForFailure (/Users/Ut/Fitternity/metropolis/node_modules/elasticsearch/src/lib/transport.js:252:7)
at HttpConnector.<anonymous> (/Users/Ut/Fitternity/metropolis/node_modules/elasticsearch/src/lib/connectors/http.js:155:
7)
at IncomingMessage.wrapper (/Users/Ut/Fitternity/metropolis/node_modules/elasticsearch/node_modules/lodash/index.js:3095
:19)
at emitNone (events.js:91:20)
at IncomingMessage.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:926:12)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickDomainCallback (internal/process/next_tick.js:122:9)
status: 400,
displayName: 'BadRequest',
message: 'Bad Request' } 'No handler found for uri [/myindex1] and method [POST]' 400
[ 'No handler found for uri [/myindex1] and method [POST]' ]
答案 0 :(得分:0)
您还需要更新JavaScript客户端并使用apiVersion
parameter set to 5.0
var esClient = new elasticsearch.Client({
host: config.es.host,
log: 'error',
apiVersion: '5.0'
});
原因是,作为ES 5.0,无法使用POST
HTTP方法创建新索引,但只能使用PUT
方法