Kusto(ADX)多JSON文件Ingestion成功但仅插入空记录求助
排查与解决方案
1. 确认JSON文件格式是否符合Kusto要求
Kusto导入多JSON时,有两种支持的格式:
- NewLine-delimited JSON(NDJSON):每行一个独立的JSON对象,比如
{"id":1,"name":"Alice"} {"id":2,"name":"Bob"} - JSON数组格式:整个文件是一个JSON数组,每个元素是一条记录,比如
[{"id":1},{"id":2}],这种情况需要指定format=multijson参数。
如果你的文件格式不符合上述两种,比如JSON对象没有分行或数组嵌套层级不对,Kusto会解析失败,仅插入空记录。
- 验证方法:通过外部表查看原始数据:
external table MyExternalTable (Text:string) storage path = 'https://<storage-account>.dfs.core.windows.net/<container>/<path>/?<sas-token>' format = raw; MyExternalTable | take 10 | project Text
2. 检查字段映射的准确性
- 映射的字段名、数据类型必须和JSON中的键完全匹配(区分大小写),比如JSON里是
userId,映射里写UserId会导致字段为空。 - 查看当前映射详情:
.show table MyTable ingestion json mappings - 修正映射示例:
.create-or-alter table MyTable ingestion json mapping "MyMapping" '[' ' {"column": "UserId", "path": "$.userId", "datatype": "string"},' ' {"column": "LoginTime", "path": "$.loginTime", "datatype": "datetime"}' ']'
3. 修正.ingest命令参数
根据JSON格式选择正确的命令参数:
- 针对NDJSON格式:
.ingest into table MyTable ( h@'https://<storage-account>.dfs.core.windows.net/<container>/<path>/?<sas-token>' ) with ( format = "json", ingestionMappingReference = "MyMapping" ) - 针对JSON数组格式:
.ingest into table MyTable ( h@'https://<storage-account>.dfs.core.windows.net/<container>/<path>/?<sas-token>' ) with ( format = "multijson", ingestionMappingReference = "MyMapping" )
注意:不要省略format参数,自动检测可能出现误判。
4. 排查隐性Ingestion错误
即使HasErrors==False,也可能存在未触发错误的解析问题,通过以下命令查看日志:
.show ingestion failures | where Database == "<你的数据库名>" and Table == "<你的表名>" | order by Timestamp desc
或者查看操作详情:
.show operations | where Operation == "DataIngestPull" and Database == "<你的数据库名>" | order by StartedOn desc | project StartedOn, OperationId, Status, Detail
5. 最小化测试验证
先导入单条测试数据,确认表和映射本身无问题:
.ingest inline into table MyTable with (format = "json") [ {"userId": "user001", "loginTime": "2024-05-20T10:00:00Z"} ]
如果这条能成功写入,说明问题出在源文件格式或批量导入的配置上。
内容的提问来源于stack exchange,提问作者Tushar Kadam
相关产品推荐
相关产品推荐

