From 18c360c9f863532dbef6c1692f407960720979e2 Mon Sep 17 00:00:00 2001 From: VBoss Date: Tue, 1 Jun 2021 15:54:40 +0200 Subject: [PATCH] Added NestedObject --- src/Mapping/Settings/Mapping/NestedObject.php | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/Mapping/Settings/Mapping/NestedObject.php 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', + ]; + } + +}