diff --git a/src/Mapping/Settings/Mapping/NestedObject.php b/src/Mapping/Settings/Mapping/NestedObject.php new file mode 100644 index 0000000..8348398 --- /dev/null +++ b/src/Mapping/Settings/Mapping/NestedObject.php @@ -0,0 +1,58 @@ +name = $name; + $this->fields = $fields; + } + + + public function key(): string + { + return $this->name; + } + + + public function toArray(): array + { + $fields = []; + /** @var \Spameri\ElasticQuery\Mapping\Settings\Mapping\FieldInterface $field */ + foreach ($this->fields as $field) { + if ($field instanceof \Spameri\ElasticQuery\Mapping\Settings\Mapping\FieldObject) { + $fields[$field->key()] = $field->toArray(); + continue; + } + if ($field instanceof \Spameri\ElasticQuery\Mapping\Settings\Mapping\FieldCollection) { + $fields[$field->key()] = $field->toArray(); + continue; + } + + $fields[$field->key()] = $field->toArray()[$field->key()]; + } + + return [ + 'properties' => $fields, + 'type' => 'nested', + ]; + } + +}