I'm running into an issue trying to use mutate to convert and XML file. I can convert the first level, but if the XML file has multiple elements then they output as string.
Logstash Configuration
filter {
if [fields][log] == "INSPECTION_AOI" {
xml {
source => "message"
store_xml => true
target => "Inspection"
remove_field => [
"message"
]
}
mutate {
convert => {
"[Inspection][CycleTime]" => "integer"
"[Inspection][TotalFeatures]" => "integer"
"[Inspection][TotalComponents]" => "integer"
"[Inspection][LotSize]" => "integer"
"[Inspection][Board][0][TotalFeatures][Value]" => "integer"
"[Inspection][Board][0][TotalComponents][Value]" => "integer"
"[Inspection][Board][0][Component][0][IncludedInCurrentVariant]" => "boolean"
"[Inspection][Board][0][Component][0][TotalFeatures]" => "integer"
"[Inspection][Board][0][Component][0][Feature][0][Inspection][0][Measurements][0][X][0][Value]" => "float"
"[Inspection][Board][0][Component][0][Feature][0][Inspection][0][Measurements][0][X][0][Minimum]" => "float"
"[Inspection][Board][0][Component][0][Feature][0][Inspection][0][Measurements][0][X][0][Maximum]" => "float"
"[Inspection][Board][0][Component][0][Feature][0][Inspection][0][Measurements][0][X][0][Target]" => "float"
"[Inspection][Board][0][Component][0][Feature][0][Inspection][0][Measurements][0][Y][0][Value]" => "float"
"[Inspection][Board][0][Component][0][Feature][0][Inspection][0][Measurements][0][Y][0][Minimum]" => "float"
"[Inspection][Board][0][Component][0][Feature][0][Inspection][0][Measurements][0][Y][0][Maximum]" => "float"
"[Inspection][Board][0][Component][0][Feature][0][Inspection][0][Measurements][0][Y][0][Target]" => "float"
"[Inspection][Board][0][Component][0][Feature][0][Inspection][0][Measurements][0][ConfidenceLevel][0][Value]" => "float"
"[Inspection][Board][0][Component][0][Feature][0][Inspection][0][Measurements][0][ConfidenceLevel][0][Minimum]" => "float"
"[Inspection][Board][0][Component][0][Feature][0][Inspection][0][Measurements][0][ConfidenceLevel][0][Maximum]" => "float"
"[Inspection][Board][0][Component][0][Feature][0][Inspection][0][Measurements][0][ConfidenceLevel][0][Target]" => "float"
}
}
}
}
output {
if [fields][log] == "INSPECTION_AOI" {
elasticsearch {
hosts => "localhost"
index => "inspection_aoi"
}
stdout { codec => rubydebug }
}
}
File 1 (XML)
<Panel Id="1" Name="Panel" PanelStatus="Failed" StartTime="04/10/2019 09:09:07" EndTime="04/10/2019 09:11:12" CycleTime="4" TotalFeatures="7704" TotalComponents="7704" LotCode="TEST" LotSize="0" Barcode="10695 05 A07502 4718" Code="10695 05 A07502 4718" NG_Stacker_SlotNumber="">
<Board Id="1" Name="Board1" BoardStatus="Failed" TotalFeatures="7704" TotalComponents="7704" Barcode="" Skip="false">
<Component Id="6" Name="C1_D1" PartNumber="LED" Package="LED" Barcode="" IncludedInCurrentVariant="false" ComponentStatus="Passed" TotalFeatures="1">
<Feature Id="7" Identifier="Body" FeatureStatus="Passed" FeatureInspectionInfo="" MeasurementValid="">
<Inspection Identifier="Appearance" Type="AI2" status="Passed">
<Measurements>
<X Value="-0.006" Minimum="-0.079999999999886329" Maximum="0.0800000000001137" Target="0" />
<Y Value="-0.006" Minimum="-0.079999999999886329" Maximum="0.0800000000001137" Target="0" />
<ConfidenceLevel Value="-0.006" Minimum="-0.079999999999886329" Maximum="0.0800000000001137" Target="0" />
</Measurements>
</Inspection>
</Feature>
</Component>
</Board>
</Panel>
File 2 (XML)
<Panel Id="1" Name="Panel" PanelStatus="Failed" StartTime="04/10/2019 09:09:07" EndTime="04/10/2019 09:11:12" CycleTime="4" TotalFeatures="7704" TotalComponents="7704" LotCode="TEST" LotSize="0" Barcode="10695 05 A07502 4718" Code="10695 05 A07502 4718" NG_Stacker_SlotNumber="">
<Board Id="1" Name="Board1" BoardStatus="Failed" TotalFeatures="7704" TotalComponents="7704" Barcode="" Skip="false">
<Component Id="6" Name="C1_D1" PartNumber="LED" Package="LED" Barcode="" IncludedInCurrentVariant="false" ComponentStatus="Passed" TotalFeatures="1">
<Feature Id="7" Identifier="Body" FeatureStatus="Passed" FeatureInspectionInfo="" MeasurementValid="">
<Inspection Identifier="Appearance" Type="AI2" status="Passed">
<Measurements>
<X Value="-0.006" Minimum="-0.079999999999886329" Maximum="0.0800000000001137" Target="0" />
<Y Value="-0.006" Minimum="-0.079999999999886329" Maximum="0.0800000000001137" Target="0" />
<ConfidenceLevel Value="-0.006" Minimum="-0.079999999999886329" Maximum="0.0800000000001137" Target="0" />
</Measurements>
</Inspection>
<Inspection Identifier="Appearance" Type="AI2" status="Passed">
<Measurements>
<X Value="-0.006" Minimum="-0.079999999999886329" Maximum="0.0800000000001137" Target="0" />
<Y Value="-0.006" Minimum="-0.079999999999886329" Maximum="0.0800000000001137" Target="0" />
<ConfidenceLevel Value="-0.006" Minimum="-0.079999999999886329" Maximum="0.0800000000001137" Target="0" />
</Measurements>
</Inspection>
<Inspection Identifier="Appearance" Type="AI2" status="Passed">
<Measurements>
<X Value="-0.006" Minimum="-0.079999999999886329" Maximum="0.0800000000001137" Target="0" />
<Y Value="-0.006" Minimum="-0.079999999999886329" Maximum="0.0800000000001137" Target="0" />
<ConfidenceLevel Value="-0.006" Minimum="-0.079999999999886329" Maximum="0.0800000000001137" Target="0" />
</Measurements>
</Inspection>
</Feature>
</Component>
</Board>
</Panel>
Result
File 1 - ConfidenceLevel, Y, X come in a FLOAT for index 0
File 2 - ConfidenceLevel, Y, X come in a FLOAT for index 0
File 2 - ConfidenceLevel, Y, X come in a STRING for index 1
File 2 - ConfidenceLevel, Y, X come in a STRING for index 2
I realize I'm only converting the first index of the XML in my logstash configuration. Is there a way to define a dynamic value for the index instead of hardcoding a [0].