jeudi 29 novembre 2018

Error creating elasticsearch mapping with elasticquent lib

In my Laravel 5.7 app I try to work with elasticsearch with composer.json :

{
    "require": {
        ...
        "elasticquent/elasticquent": "dev-master",
        ...
    },

reading article https://appdividend.com/2018/06/30/laravel-elasticsearch-tutorial-example/ I want to start with creting mapping and bulking data. For this in my model app/Vote.php:

namespace App;

use DB; ... use Elasticquent\ElasticquentTrait; ... class Vote extends MyAppModel { use ElasticquentTrait; ...

protected $table = 'votes';
protected $primaryKey = 'id';
public $timestamps = false;

protected $fillable = ['name', 'slug', 'description', 'creator_id', 'vote_category_id', 'is_quiz', 'status', 'image'];
protected $mappingProperties = array(

    'id'               => [
        'type' => 'integer',
        "analyzer" => "standard",
        'include_in_all' => FALSE
    ], //            'user'    => array(  // THERE would be nested data later //                'type' => 'object', //               

'properties' => array( // 'name' => array('type' => 'string', 'include_in_all' => TRUE), //
'fullName' => array('type' => 'string', 'include_in_all' => TRUE, 'boost' => 2) // ), // ), 'name' => [ 'type' => 'string', "analyzer" => "standard", 'include_in_all' => TRUE ], 'slug' => [ 'type' => 'string', "analyzer" => "standard", 'include_in_all' => TRUE ], 'description' => [ 'type' => 'string', "analyzer" => "standard", 'include_in_all' => FALSE ], 'created_at' => [ 'type' => 'date', "analyzer" => "standard", 'include_in_all' => FALSE ],

public function getTableName(): string
{
    return $this->table;
}

public function getPrimaryKey(): string
{
    return $this->primaryKey;
}



public static function setVotesElasticMapping()
{

// Vote::deleteMapping();

    Vote::createIndex(/*$shards = null, $replicas = null*/);

    Vote::putMapping(/*$ignoreConflicts = true*/);

    Vote::addAllToIndex ();
}

}

But calling method setVotesElasticMapping I got error:

{"error":{"root_cause":[{"type":"resource_already_exists_exception","reason":"index [select_vote/IxHrJ300SIWSZ_s12-jAJw] already exists","index_uuid":"IxHrJ300SIWSZ_s12-jAJw","index":"select_vote"}],"type":"resource_already_exists_exception","reason":"index [select_vote/IxHrJ300SIWSZ_s12-jAJw] already exists","index_uuid":"IxHrJ300SIWSZ_s12-jAJw","index":"select_vote"},
"status":400}

That is clear, as I have created the index before and "select_vote" is "default_index" in config/elasticquent.php file. But uncommenting line

Vote::deleteMapping();

I got error :

Elasticsearch \ Common \ Exceptions \ BadRequest400Exception (405)
{"error":"Incorrect HTTP method for uri [/select_vote/votes/_mapping] and method [DELETE], allowed: [PUT, GET, POST]","status":405}

Can you say why error and how to fix it? I think anyway I need this method calling, say if I remade structure of mapping...

Thanks!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire