JSON 對應
當您的擷取來源檔案為 JSON 格式時,請使用 JSON 對應,將傳入數據對應至數據表中的數據行。
對應清單中的每個元素都會定義特定數據行的對應。 這些元素是從三個屬性建構而成: column
、 datatype
和 properties
。 深入了解 數據對應概觀。
每個 JSON 對應元素都必須包含下列任一選擇性屬性:
屬性 | 類型 | 描述 |
---|---|---|
路徑 | string |
如果值以它開頭 $ 會解譯為 JSON 檔中欄位的 JSON 路徑,而該欄位將會成為數據表中數據行的內容。 表示整個檔案的 JSON 路徑為 $ 。 如果值不是以 $ 它開頭,則會解譯為常數值。 包含特殊字元的 JSON 路徑應以 ['Property Name'] 的形式逸出。 如需詳細資訊,請參閱 JSONPath 語法。 |
ConstValue | string |
要用於數據行的常數值,而不是 JSON 檔案內的某些值。 |
轉換 | string |
應該在具有 對應轉換的內容上套用的轉換。 |
重要
針對佇列擷取:
- 如果對應中所參考的數據表不存在於資料庫中,就會自動建立它,前提是所有數據行都指定了有效的數據類型。
- 如果對應中參考的數據行不存在於數據表中,它會在第一次為該數據行內嵌數據時自動加入數據表,因為數據行指定了有效的數據類型。 若要將新數據行新增至對應,請使用 .alter ingestion 對應命令。
- 數據會使用擷取屬性進行批處理。 所使用的更相異擷取對應屬性,例如不同的 ConstValue 值,擷取變得越分散,這可能會導致效能降低。
範例
[
{"Column": "event_timestamp", "Properties": {"Path": "$.Timestamp"}},
{"Column": "event_name", "Properties": {"Path": "$.Event.Name"}},
{"Column": "event_type", "Properties": {"Path": "$.Event.Type"}},
{"Column": "source_uri", "Properties": {"Transform": "SourceLocation"}},
{"Column": "source_line", "Properties": {"Transform": "SourceLineNumber"}},
{"Column": "event_time", "Properties": {"Path": "$.Timestamp", "Transform": "DateTimeFromUnixMilliseconds"}},
{"Column": "ingestion_time", "Properties": {"ConstValue": "2021-01-01T10:32:00"}},
{"Column": "full_record", "Properties": {"Path": "$"}}
]
在管理命令中提供 .ingest
上述對應時,會串行化為 JSON 字串。
.ingest into Table123 (@"source1", @"source2")
with
(
format = "json",
ingestionMapping =
```
[
{"Column": "column_a", "Properties": {"Path": "$.Obj.Property"}},
{"Column": "column_b", "Properties": {"Path": "$.Property"}},
{"Column": "custom_column", "Properties": {"Path": "$.[\'Property name with space\']"}}
]
```
)
預先建立的對應
預先 建立對應時,請在管理命令中 .ingest
依名稱參考對應。
.ingest into Table123 (@"source1", @"source2")
with
(
format="json",
ingestionMappingReference = "Mapping_Name"
)
身分識別對應
在擷取期間使用 JSON 對應,而不定義對應架構 (請參閱 身分識別 對應) 。
.ingest into Table123 (@"source1", @"source2")
with
(
format="json"
)
複製 JSON 對應
您可以使用下列流程,複製現有資料表的 JSON 對應,並使用相同的對應來建立新的資料表:
若想要複製資料表的對應,請在該資料表上執行下列命令:
.show table TABLENAME ingestion json mappings | extend formatted_mapping = strcat("'",replace_string(Mapping, "'", "\\'"),"'") | project formatted_mapping
使用上述命令的輸出,來建立具有相同對應的新資料表:
.create table TABLENAME ingestion json mapping "TABLENAME_Mapping" RESULT_OF_ABOVE_CMD
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應