Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't populate the index with correct data #163

Open
a1tem opened this issue Jun 8, 2018 · 1 comment
Open

Can't populate the index with correct data #163

a1tem opened this issue Jun 8, 2018 · 1 comment

Comments

@a1tem
Copy link

a1tem commented Jun 8, 2018

Hello, thank you for your package it's awesome.

I have created database\mappings\app_models_knowledgebase.php

And put there:

<?php

use Sleimanx2\Plastic\Facades\Map;
use Sleimanx2\Plastic\Map\Blueprint;
use Sleimanx2\Plastic\Mappings\Mapping;

class AppModelsKnowledgeBase extends Mapping
{
    /**
     * Full name of the model that should be mapped
     *
     * @var string
     */
    protected $model = App\Models\KnowledgeBase\KnowledgeBase::class;

    /**
     * Run the mapping.
     *
     * @return void
     */
    public function map()
    {
        Map::create($this->getModelType(), function(Blueprint $map){
            $map->string('title');
            $map->string('content');
            $map->string('status');
            $map->nested('tags', function (Blueprint $map) {
                $map->integer('id');
                $map->string('name');
            });
        }, $this->getModelIndex());
    }
}

Also within my model I have:

    public function buildDocument()
    {
        return [
            'title' => $this->title,
            'content' => $this->content,
            'tags' => $this->tags,
            'status' => $this->status,
        ];
    }

    /**
     * Add tags attribute
     *
     * @return \Illuminate\Database\Eloquent\Collection
     */
    public function getTagsAttribute()
    {
        return $this->tags()->get();
    }

    /**
     * Get all of the tags for the article.
     */
    public function tags()
    {
        return $this->morphToMany(
            Tag::class,
            TagRelation::RELATION_NAME,
            TagRelation::TABLE_NAME
        );
    }

So question is how can I populate data,
when I run

artisan plastic:populate --mappings

it says:

Index « test » does not exists.

And if I try to index document before

$knowledgeBase->document()->save(); 

so then when I run

artisan mapping:rerun 

it says:

Elasticsearch\Common\Exceptions\BadRequest400Exception  : {"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"object mapping [tags] can't be changed from non-nested to nested"}],"type":"illegal_argument_exception","reason":"object mapping [tags] can't be changed from non-nested to nested"},"status":400}

@xotrs
Copy link

xotrs commented Jun 14, 2018

Try
Use Object Instead to Nested

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants