2014-02-17 38 views
0

我是很新,Node.js的 - 並希望不要問愚蠢的問題...的Node.js - 索引elasticsearch文件 - 直到infity

我試圖索引文檔到elasticsearch - 這作品。

var elasticsearch = require('elasticsearch'); 

function writetoela(information){ 
    var client = elasticsearch.Client({ 
    host: 'server03:9200' 
    }); 

    client.index({ 
     index: 'fhem', 
     type: 'state', 
     body: { 
      time: information.time, 
      alias: information.alias, 
      state: information.state, 
      room: information.room 
     } 
    })} 

我的問題始於索引文檔之後。該函數不會退出,所以我可以做其他的事情。

功能以上由下面的行稱爲:

index_data.writetoela(data); 

「數據」是值的陣列,其應該被索引到elasticsearch。

有人可以告訴我,爲什麼會發生這種情況?

感謝您

比約恩·

+0

嗨 - 只是想知道如果你設法弄清楚爲什麼函數永遠不會返回?我遇到同樣的問題,我不知道爲什麼。我已經在Windows和Ubuntu上進行了測試,並且出現了同樣的問題。 – Mike

+0

親愛的@MY,我最終使用了elasticsearch的REST API和[http](http://nodejs.org/api/http.html)...作品非常簡單,你只需要通讀彈性搜索的REST API文檔...(它們提供了示例...)。 – bjoernhoefer

+0

很酷。感謝您的回覆! – Mike

回答

0

對於我來說,應該是一個:

var elasticsearch = require('elasticsearch'); 

    function writetoela(information){ 
    var client = elasticsearch.Client({ 
    host: 'server03:9200' 
    }); 

    client.index({ 
     index: 'fhem', 
     type: 'state', 
     body: { 
      time: information.time, 
      alias: information.alias, 
      state: information.state, 
      room: information.room 
     } 
    }, function (err, resp) { 
      // handle the error response here 
      console.info(err); 
      console.info(resp); 
    }); 

對於調試應用程序使用nodeinspector: https://github.com/node-inspector/node-inspector