2017-05-09 62 views
0

我在Kibana中遇到問題,在以下行中解釋了字段value。我會盡力解釋這種情況。實際值無法識別從Kinesis Firehose發送JSON數據到elasticsearch

我將dynamoDB流發送到Lambda,然後發送到Kenesis Firehouse,最後從Firehose發送到Elasticsearch。我使用Kibana來可視化數據,這裏是我遇到問題的地方。

比方說,我要送這個JSON來DynamoDB:

拉姆達我收到以下:

{ 
    "data": { 
     "M": { 
      "machine": { 
       "M": { 
        "application": { 
         "S": "application" 
        }, 
        "brand": { 
         "S": "band" 
        } 
       } 
      }, 
      "description": { 
       "S": "This is the description" 
      }, 
      "id": { 
       "S": "identificator" 
      }, 
      "units": { 
       "S": "units" 
      }, 
      "value": { 
       "N": "33" 
      }, 
      "_msgid": { 
       "S": "85209b75.f51ee8" 
      }, 
      "timestamp": { 
       "S": "2017-05-09T06:38:00.337Z" 
      } 
     } 
    }, 
    "id": { 
     "S": "85209b75.f51ee8" 
    } 
} 

如果我轉發這最後JSON來室壁運動流水,在Kibana時我配置索引模式,它自動識別"timestamp"(這很好)。這裏的問題是字段"value"就像一個字符串,它不被識別。

我試圖修改JSON,然後再發送到流水,但隨後Kibana不承認"timestamp"

{ 
    "data": { 
     "machine": { 
      "application": "application", 
      "brand": "brand" 
     }, 
     "description": "This is the description", 
     "id": "identificator", 
     "units": "KWh", 
     "value": 33, 
     "_msgid": "85209b75.f51ee8", 
     "timestamp": "2017-05-09T06:38:00.337Z" 
    }, 
    "id": "85209b75.f51ee8" 
} 

我想知道我怎麼能發送這個數據和Kibana承認「時間戳「和」值「字段。

這是我使用的拉姆達的代碼示例:

var AWS = require('aws-sdk'); 
var unmarshalJson = require('dynamodb-marshaler').unmarshalJson; 

var firehose = new AWS.Firehose(); 

exports.lambda_handler = function(event, context) { 

    var record = JSON.stringify(event.Records[0].dynamodb.NewImage); 

    console.log("[INFO]:"+JSON.stringify(event.Records[0].dynamodb.NewImage)); 

    var params = { 
     DeliveryStreamName: 'DeliveryStreamName', 

     Record:{ 
      Data: record 
     } 
    }; 
    firehose.putRecord(params, function(err, data) { 

     if (err) console.log(err, err.stack); // an error occurred 
     else  console.log(JSON.stringify(data));   // successful response 

     context.done(); 
    }); 
}; 

回答

0

我解決它通過創建自己的索引映射,而不是讓室壁運動流水創建它。並聲明"timestamp"屬性作爲{ "type" : "date" }"value" attibute爲{ "type" : "float" }

例如,對於這種類型的JSON的:

{ 
    "data": { 
     "timestamp": "2017-05-09T11:30:41.484Z", 
     "tag": "tag", 
     "value": 33, 
     "units": "units", 
     "type": "type", 
     "machine":{ 
      "name": "name", 
      "type": "type", 
      "company": "company" 
     } 
    }, 
    "id": "85209b75.f51ee8" 
} 

我手動創建以下elasticsearch指數和映射:

PUT /index 
{ 
    "settings" : { 
     "number_of_shards" : 2 
    }, 
    "mappings" : { 
     "type" : { 
      "properties" : { 
       "data" : { 
        "properties" : { 
         "machine":{ 
          "properties": { 
           "name": { "type" : "text" }, 
           "type": { "type" : "text" }, 
           "company": { "type" : "text" } 
          } 
         }, 
         "timestamp": { "type" : "date" }, 
         "tag" : { "type" : "text" }, 
         "value": { "type" : "float" }, 
         "description": { "type" : "text" }, 
         "units": { "type" : "text" }, 
         "type" : { "type" : "text" }, 
         "_msgid": { "type" : "text" } 
        } 
       }, 
       "id": { "type" : "text" }  
      } 
     } 
    } 
} 

所以,爲了解決這個問題,我認爲在lambda中你需要檢查索引映射是否存在,如果不是你自己創建的更好的解決方案。

相關問題