Allow a more dynamic mapping for dynamic templates
This commit is contained in:
parent
ab792952c1
commit
eaf52fa907
|
@ -341,16 +341,7 @@ class Configuration implements ConfigurationInterface
|
|||
->children()
|
||||
->scalarNode('match')->isRequired()->end()
|
||||
->scalarNode('match_mapping_type')->end()
|
||||
->arrayNode('mapping')
|
||||
->isRequired()
|
||||
->children()
|
||||
->scalarNode('type')->end()
|
||||
->scalarNode('index')->end()
|
||||
->arrayNode('fields')
|
||||
->children()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->append($this->getDynamicTemplateMapping())
|
||||
->end()
|
||||
->end()
|
||||
;
|
||||
|
@ -358,6 +349,21 @@ class Configuration implements ConfigurationInterface
|
|||
return $node;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the array node used for mapping in dynamic templates
|
||||
*/
|
||||
protected function getDynamicTemplateMapping()
|
||||
{
|
||||
$builder = new TreeBuilder();
|
||||
$node = $builder->root('mapping');
|
||||
|
||||
$nestings = $this->getNestingsForDynamicTemplates();
|
||||
|
||||
$this->addFieldConfig($node->children(), $nestings);
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Symfony\Component\Config\Definition\Builder\NodeBuilder $node The node to which to attach the field config to
|
||||
* @param array $nestings the nested mappings for the current field level
|
||||
|
@ -451,6 +457,41 @@ class Configuration implements ConfigurationInterface
|
|||
return $nestings;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array The unique nested mappings for all dynamic templates
|
||||
*/
|
||||
protected function getNestingsForDynamicTemplates()
|
||||
{
|
||||
if (!isset($this->configArray[0]['indexes'])) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$nestings = array();
|
||||
foreach ($this->configArray[0]['indexes'] as $index) {
|
||||
if (empty($index['types'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($index['types'] as $type) {
|
||||
if (empty($type['dynamic_templates'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($type['dynamic_templates'] as $definition) {
|
||||
$field = $definition['mapping'];
|
||||
|
||||
if (isset($field['fields'])) {
|
||||
$this->addPropertyNesting($field, $nestings, 'fields');
|
||||
} else if (isset($field['properties'])) {
|
||||
$this->addPropertyNesting($field, $nestings, 'properties');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return $nestings;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $mappings The mappings for the current type
|
||||
* @return array The nested mappings defined for this type
|
||||
|
|
Loading…
Reference in a new issue