在我的例子中,NIFI 將從系統日志防火墻接收資料,然后在轉換后將 JSON 發送到 ELASTIC。這是我第一次接觸 ELASTICSEARCH
{
"LogChain" : "Corp01 input",
"src_ip" : "162.142.125.228",
"src_port" : "61802",
"dst_ip" : "177.16.1.13",
"dst_port" : "6580",
"timestamp_utc" : 1646226066899
}
在 Elasticsearch 中自動創建了具有此型別別的索引
{
"mt-firewall" : {
"mappings" : {
"properties" : {
"LogChain" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"dst_ip" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"dst_port" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"src_ip" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"src_port" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"timestamp_utc" : {
"type" : "long"
}
}
}
}
}
如何更改 Elasticsearch 中的型別欄位?
- “src_ip”:輸入“ip”
- “dst_ip”:輸入“ip”
- “timestamp_utc”:輸入“資料”
uj5u.com熱心網友回復:
您可以使用 Elasticsearch 中的映射以及我在下面給出的一些方式來更改或配置欄位型別:
1.顯式索引映射
在這里,您將在將任何檔案索引到 Elasticsearch 之前,自行定義所有必需欄位和特定型別欄位的索引映射。
PUT /my-index-000001
{
"mappings": {
"properties": {
"src_ip": { "type": "ip" },
"dst_ip": { "type": "ip" },
"timestamp_utc": { "type": "date" }
}
}
}
2.動態模板:
在這里,您將在創建索引時提供動態模板,并根據條件 ES 將映射具有特定資料型別的欄位,例如欄位名稱是否以_ip然后映射欄位作為ip型別。
PUT my-index-000001/
{
"mappings": {
"dynamic_templates": [
{
"strings_as_ip": {
"match_mapping_type": "string",
"match": "*ip",
"runtime": {
"type": "ip"
}
}
}
]
}
}
更新1:
如果要更新現有索引中的映射,則不建議這樣做,因為它會創建不一致的資料。
您可以按照以下步驟操作:
- Use Reindex API to copy data to temp index.
- Delete your original index.
- define index with one of the above one method with index mapping.
- Use Reindex API to copy data from temp index to original index (newly created index with Mapping)
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/437231.html
標籤:弹性搜索
