@@ -173,12 +173,16 @@ def prune_mappings_of_unsupported_types(
173173 delete_nested_key_from_dict (stream_mappings , field_name )
174174 nested_flattened_fields = find_flattened_fields_with_subfields (stream_mappings )
175175 for field in nested_flattened_fields :
176+ # Remove both .fields and .properties entries for flattened fields
177+ # properties entries can occur when being merged with non-ecs or custom schemas
176178 field_name = str (field ).split (".fields." )[0 ].replace ("." , ".properties." ) + ".fields"
179+ property_name = str (field ).split (".fields." )[0 ].replace ("." , ".properties." ) + ".properties"
177180 log (
178181 f"Warning: flattened field `{ field } ` found in `{ integration } -{ stream } ` with sub fields. "
179182 f"Removing parent field from schema for ES|QL validation."
180183 )
181184 delete_nested_key_from_dict (stream_mappings , field_name )
185+ delete_nested_key_from_dict (stream_mappings , property_name )
182186 return stream_mappings
183187
184188
@@ -246,12 +250,13 @@ def get_index_to_package_lookup(indices: list[str], index_lookup: dict[str, Any]
246250 return index_lookup_indices
247251
248252
249- def get_filtered_index_schema (
253+ def get_filtered_index_schema ( # noqa: PLR0913
250254 indices : list [str ],
251255 index_lookup : dict [str , Any ],
252256 ecs_schema : dict [str , Any ],
253257 non_ecs_mapping : dict [str , Any ],
254258 custom_mapping : dict [str , Any ],
259+ log : Callable [[str ], None ],
255260) -> tuple [dict [str , Any ], dict [str , Any ]]:
256261 """Check if the provided indices are known based on the integration format. Returns the combined schema."""
257262
@@ -304,7 +309,7 @@ def get_filtered_index_schema(
304309 # Need to use a merge here to not overwrite existing fields
305310 utils .combine_dicts (base , deepcopy (non_ecs_mapping .get (match , {})))
306311 utils .combine_dicts (base , deepcopy (custom_mapping .get (match , {})))
307- filtered_index_lookup [match ] = base
312+ filtered_index_lookup [match ] = prune_mappings_of_unsupported_types ( "index" , match , base , log )
308313 utils .combine_dicts (combined_mappings , deepcopy (base ))
309314
310315 # Reduce the index lookup to only the matched indices (remote/Kibana schema validation source of truth)
@@ -413,6 +418,9 @@ def find_flattened_fields_with_subfields(mapping: dict[str, Any], path: str = ""
413418 # Check if the field is of type 'flattened' and has a 'fields' key
414419 if properties .get ("type" ) == "flattened" and "fields" in properties : # type: ignore[reportUnknownVariableType]
415420 flattened_fields_with_subfields .append (current_path ) # type: ignore[reportUnknownVariableType]
421+ # Check if the field is of type 'flattened' and has a 'properties' key
422+ if properties .get ("type" ) == "flattened" and "properties" in properties : # type: ignore[reportUnknownVariableType]
423+ flattened_fields_with_subfields .append (current_path ) # type: ignore[reportUnknownVariableType]
416424
417425 # Recurse into subfields
418426 if "properties" in properties :
@@ -506,7 +514,7 @@ def prepare_mappings( # noqa: PLR0913
506514
507515 # Filter combined mappings based on the provided indices
508516 combined_mappings , index_lookup = get_filtered_index_schema (
509- indices , index_lookup , ecs_schema , non_ecs_mapping , custom_mapping
517+ indices , index_lookup , ecs_schema , non_ecs_mapping , custom_mapping , log
510518 )
511519
512520 index_lookup .update ({"rule-ecs-index" : ecs_schema })
0 commit comments