pdphilip / laravel-opensearch

An OpenSearch implementation of Laravel's Eloquent ORM
https://opensearch.pdphilip.com/
MIT License
23 stars 2 forks source link

How to save nested data type #7

Closed gavnyx closed 6 days ago

gavnyx commented 1 week ago

Hi, I have a question, how to save record to nested data type with this package ?

example field map like this :

"authors": {
    "type": "nested",
    "include_in_parent": true,
    "properties": {
        "id": {
            "type": "text"
        },
        "name": {
            "type": "text"
        }
    }
},
pdphilip commented 6 days ago

Hey @gavnyx , you can just save the PHP array in the field:

$authors = [
   [id => '', name => ''],
   [id => '', name => ''],
   [id => '', name => ''],
    ...
];

$model->authors = $authors;
$model->save();

See https://opensearch.pdphilip.com/nested-queries for querying nested data