2014-10-02 150 views
5

我是ElasticSearch和Kibana的新手,很難讓Kibana識別我的時間戳。識別Kibana和ElasticSearch中的時間戳

我有一個JSON文件,裏面有很多我想用Curl插入Elasticsearch的數據。以下是其中一個JSON條目的示例。

{"index":{"_id":"63"}} 
{"account_number":63,"firstname":"Hughes","lastname":"Owens", "email":"[email protected]", "_timestamp":"2013-07-05T08:49:30.123"} 

我曾嘗試使用命令中Elasticsearch創建索引:

curl -XPUT 'http://localhost:9200/test/' 

然後我試圖建立起來用於時間戳的適當的映射:

curl -XPUT 'http://localhost:9200/test/container/_mapping' -d' 
{ 
"container" : { 
"_timestamp" : { 
"_timestamp" : {"enabled: true, "type":"date", "format": "date_hour_minute_second_fraction", "store":true} 
} 
} 
}' 

//時間戳的格式從http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-date-format.html

然後我試圖批量插入我的數據:

curl -XPOST 'localhost:9200/test/container/_bulk?pretty' --data-binary @myfile.json 

所有這些命令的運行,而不但是當數據以Kibana被觀看的_timestamp場不被認可的錯。通過時間戳排序不起作用,嘗試使用不同的時間段過濾數據不起作用。關於這個問題發生的原因的任何想法都受到了應用。

回答

6

管理解決問題。因此,對於任何人有這個問題:

我們有我們的約會保存格式是不正確的,是需要:

"_timestamp":"2013-07-05 08:49:30.123" 

然後我們的映射需要的是:

curl -XPUT 'http://localhost:9200/test/container/_mapping' -d' 
{ 
"container" : { 
"_timestamp" : {"enabled": true, "type":"date", "format": "yyyy-MM-dd HH:mm:ss.SSS", "store":true, "path" : "_timestamp"} 
} 
}' 

希望這幫助某人。

+0

你的數據本身具有_timestamp領域JSON鍵值對?映射是否使elasticsearch插入時間戳? – liv2hak 2015-03-31 21:00:37

+1

使用最新版本的Elastic Search(5.1.1)我必須使用以下格式:''timestamp「:」2016-12-15T11:34:10.000「'。請注意'T'和字段名稱'_timestamp'未被接受。 – Marc 2016-12-15 15:04:34

+0

@Marc非常感謝你!在日期和時間之間使用「T」在5.3上仍然運行良好 – Marcel 2017-04-16 08:24:55

5

如果您有一個新紀元時間戳,則無需製作和ISO8601日期。爲了讓Kibana識別該字段,因爲日期必須是日期字段。

請注意,您必須將字段設置爲日期類型之前您將任何數據輸入到/ index/type。否則它將被存儲爲長期且不可更改。

簡單的例子,可以被粘貼到marvel/sense插件:每個系列這些命令

# Make sure the index isn't there 
DELETE /logger 

# Create the index 
PUT /logger 

# Add the mapping of properties to the document type `mem` 
PUT /logger/_mapping/mem 
{ 
    "mem": { 
    "properties": { 
     "timestamp": { 
     "type": "date" 
     }, 
     "free": { 
     "type": "long" 
     } 
    } 
    } 
} 

# Inspect the newly created mapping 
GET /logger/_mapping/mem 

運行。

生成自由MEM日誌

下面是一個簡單的腳本回顯到終端和日誌到您的本地elasticsearch:

while ((1==1)); do memfree=`free -b|tail -n 1|tr -s ' ' ' '|cut -d ' ' -f4`; echo $load; curl -XPOST "localhost:9200/logger/mem" -d "{ \"timestamp\": `date +%s%3N`, \"free\": $memfree }"; sleep 1; done 

檢查數據彈性搜索

中粘貼此您marvel/sense

GET /logger/mem/_search 

現在你可以移動到Kibana並做一些圖表。 Kibana會自動檢測你的日期字段。