2017-04-03 72 views
0

我試圖使用npm包elasticsearch創建索引,並且已經收到以下錯誤。'爲uri [/ myindex]和方法[POST]找到沒有處理程序'Elasticsearch 5.0.3 with nodejs esclient

'找到的URI [/ myindex]和方法[POST]沒有處理機'

esClient.indices.create({ index: 'myindex' }, function(err, resp, status) { cb(err, resp); });

下面的代碼所工作Elasticsearch 2.3

這裏是追蹤日誌

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

你能不能也告訴你如何建立你的' esClient'? – Val

+0

var esClient = new elasticsearch.Client({host:config.es.host, log:'error' }); –

+0

你是否更新過JavaScript客戶端? – Val

回答

0

您還需要更新您的JavaScript客戶端,並使用0來實例化它

var esClient = new elasticsearch.Client({ 
    host: config.es.host, 
    log: 'error', 
    apiVersion: '5.0' 
}); 

這樣做的原因是,隨着ES 5.0則無法使用POST HTTP方法來創建新的索引,但只能用PUT方法

+0

非常感謝。有效 :)。 –

+0

太棒了,很高興它解決了! – Val

相關問題