I have been working to script the import of an index pattern with a fields. The import appears to run successfully, but when I try to display the imported index pattern under Kibana | Index Patterns, it fails to load. All I see is a blank screen.
I'm using the following PowerShell script to create the index pattern
$url = "http://localhost:5601/api/saved_objects/index-pattern/my-pattern";
$body = @"
{
"attributes": {
"title": "my-pattern-*",
"timeFieldName": "@timestamp",
"fields": [
{
"name": "field1",
"type": "string",
"count": 0,
"scripted": false,
"searchable": true,
"aggregatable": false,
"readFromDocValues": false
}
]
}
}
"@;
$params = @{
Uri = $url;
Method = 'POST';
Headers = @{ 'kbn-xsrf' = "true" }
ContentType = 'application/json';
};
$Result = Invoke-WebRequest @params -Body $body;
Write-Host $Result.StatusCode;
Write-Host $Result;
I receive an HTTP 200 response with the following JSON
{
"type": "index-pattern",
"id": "my-pattern",
"attributes": {
"title": "my-pattern-*",
"timeFieldName": "@timestamp",
"fields": [
{
"name": "field1",
"type": "string",
"count": 0,
"scripted": false,
"searchable": true,
"aggregatable": false,
"readFromDocValues": false
}
]
},
"references": [],
"migrationVersion": {
"index-pattern": "7.11.0"
},
"coreMigrationVersion": "7.12.0",
"updated_at": "2021-09-10T13:31:54.118Z",
"version": "WzE4NDcsMTFd",
"namespaces": [
"default"
]
}
I can then see the new index pattern under Kibana | Index Patterns or under Kibana | Saved Objects. However, when I try to view the Index Pattern, it fails to load. The browser Dev Tools | Console shows the following message
Uncaught (in promise) SyntaxError: Unexpected token o in JSON at position 1
at JSON.parse (<anonymous>)
at index_patterns_IndexPatternsService.savedObjectToSpec (data.plugin.js:1)
at index_patterns_IndexPatternsService.getSavedObjectAndInit (data.plugin.js:1)
If I look at the Dev Tools | Network, I can see that Kibana is making a request for the data of the index pattern and it returns JSON in the _bulk_get request. It is immediately after this request that the error displays.
{
"saved_objects": [
{
"id": "my-pattern",
"type": "index-pattern",
"namespaces": [
"default"
],
"updated_at": "2021-09-10T13:31:54.118Z",
"version": "WzE4NDcsMTFd",
"attributes": {
"title": "my-pattern-*",
"timeFieldName": "@timestamp",
"fields": [
{
"name": "field1",
"type": "string",
"count": 0,
"scripted": false,
"searchable": true,
"aggregatable": false,
"readFromDocValues": false
}
]
},
"references": [],
"migrationVersion": {
"index-pattern": "7.11.0"
},
"coreMigrationVersion": "7.12.0"
}
]
}
If I import the index pattern without the fields attribute, it imports successfully.
Any thoughts on what's wrong?