1 month ago

How to include elastic search resource in nova

Posted 1 month ago by cannycookie

I have an elasticsearch instance with 5 million rows and rather than duplicate these data into our db, I have a places table with just an id which matches the ES id. In theory i can then join our places record to other relations in our database.

My Place Model looks like this but only the id (and relations) actually exist in mysql.

 * @property string $id
 * @property integer $accounts_id
 * @property string $name
 * @property Account $account
 * @property string $address
 * @property string $city
 * @property string $province
 * @property string $postalCode
 * @property string $country
 * @property array $descriptions
 * @property array $imageURLs
 * @property string $created_at
 * @property string $updated_at
 * @property PlacePost[] $placePosts
 * @property Submission[] $submissions
 * @property Survey[] $surveys
 * @property UserPlaceAlert[] $userPlaceAlerts
class Place extends Model
    use Searchable, CustomSearch;

     * @var array
    protected $fillable = ['id','name','address','city','province','postalCode','country','imageURLs','descriptions'];

When an ES record is found, I populate a new places model

    public static function elasticSearchToModel($es)
        $place = new Place($es['_source']);
        $place->id = $es['_id'];
        $place->created_at = $es['_source']['dateAdded'];
        $place->updated_at = $es['_source']['dateUpdated'];
        return $place;

Which then allows us to create related records not in ES.

Can anyone tell me if it's feasible to create custom CRUD functions to map changes back to ES AND do this within Nova?

If someone knows nova well enough I'm sure it's not that hard, would be happy to pay for some assistance with this, unless someone's done it already?

Thanks for any advice ;-)

Please sign in or create an account to participate in this conversation.