2016-11-29 89 views
0

我想我的手在ELK堆棧上。我的Kibana有問題。我的數據中的一個字段的類型是整型,但在Kibana上它顯示的類型爲undefined。請在下面找到我正在使用的示例數據。Kibana沒有采取數據類型

{ 
     "took": 6, 
     "timed_out": false, 
     "_shards": { 
     "total": 5, 
     "successful": 5, 
     "failed": 0 
     }, 
     "hits": { 
     "total": 1, 
     "max_score": 1, 
     "hits": [ 
      { 
      "_index": "products", 
      "_type": "logs", 
      "_id": "AVivMgCnKd2m9Wr-3jBk", 
      "_score": 1, 
      "_source": { 
       "message": "product10,990\r", 
       "@version": "1", 
       "@timestamp": "2016-11-29T08:27:18.792Z", 
       "path": "/Users/B0079855/Documents/SERVERS/logstash-2.2.2/samples/products.csv", 
       "host": "LTB0079855-MAC.local", 
       "product_name": "product10", 
       "product_price": 990 
      } 
      } 
     ] 
     } 
    } 

Kibana not identify product_price as integer。

logstash的conf:

input { 
    file { 
    path => "{filepath}" 
    # to read from the beginning of file 
    start_position => beginning 
    sincedb_path => "/dev/null" 
    } 
} 

filter { 
    csv { 
     columns => ["product_name", "product_price"] 
    } 
    mutate { 
     convert => { "product_price" => "integer" } 
    } 
} 

output { 
    elasticsearch { 
     hosts => ["localhost:9200"] 
     index => "products" 
    } 
    stdout { codec => rubydebug } 
} 

如何使這項工作?

+0

我正在通過logstash從文件中讀取數據,並將其轉換爲過濾器中的整數。對於濾波器我logstash配置是這樣的:'濾波器{ CSV { 列=> [ 「PRODUCT_NAME」, 「PRODUCT_PRICE」] } 發生變異{ \t轉換=> { 「PRODUCT_PRICE」=> 「整數」} \t} }' –

+0

您能告訴我們logstash conf嗎?你想從哪種類型轉換而來?你在使用mutate插件嗎?如果你不從logstash轉換它,並通過你的映射進行更新,如我在下面的答案中提到的那樣? – Kulasangar

+0

如果我通過更新聲明執行操作,我將不得不爲每個索引執行此操作。我的logstash conf看起來像。'輸入{ 文件{ 路徑=> 「{文件路徑}」 #從文件 START_POSITION的開頭讀=>開始 sincedb_path => 「的/ dev/null的」 } } 濾波器{ CSV { 列=> [ 「PRODUCT_NAME」, 「PRODUCT_PRICE」] } 發生變異{ \t轉換=> { 「PRODUCT_PRICE」=> 「整數」} \t} } 輸出{ elasticsearch { \t個主機=> [ 「本地主機:9200」] \t \t指數=> 「產品」 \t} 標準輸出{編解碼器=> ruby​​debug} }' –

回答

1

如果你還沒有使用映射你Mapping領域,你可以不喜歡下面以創建mapping創建索引之前:

PUT要求:http://yourhost:9200/yourindex

請求體:

{ 
    "mappings": { 
    "your_type": { <--- document_type value in logstash conf 
     "properties": { 
     "product_price": { 
      "type": "integer" 
     } 
     } 
    } 
    } 
} 

如果不是,您甚至可以使用PUT映射API再次更新索引映射:

curl -XPUT 'http://localhost:9200/your_index/_mapping/your_type' -d ' 
{ 
    "yout_type" : { 
     "properties" : {    
      //your new mapping properties 
      "product_price": { 
      "type": "integer" 
      } 
     } 
    } 
}' 

希望這SO也有幫助。

編輯:

在你的情況,因爲你正在使用logstash轉換它,你tryign將其轉換csv插件之外。嘗試在插件本身內進行轉換;

filter { 
    csv { 
    columns => ["product_name", "product_price"] 
    mutate { 
     convert => { "product_price" => "integer" } 
    } 
    } 
} 
相關問題