elasticquent / Elasticquent

Maps Laravel Eloquent models to Elasticsearch types
MIT License
1.35k stars 401 forks source link

Mapping with elasticquent got Root mapping definition has unsupported parameters error #222

Open PetroGromovo opened 4 years ago

PetroGromovo commented 4 years ago

Hello, In Laravel 7.12.0 app I added "elasticquent/elasticquent": "dev-master" plugin and I try to implement sample data example from https://www.elastic.co/blog/a-practical-introduction-to-elasticsearch

with shakespeare.json file

But making mapping I got error :

Elasticsearch\Common\Exceptions\BadRequest400Exception
{"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"Root mapping definition has unsupported parameters: [shakespeares : {_source={enabled=true}, properties={play_name={analyzer=standard, type=string}, speech_number={analyzer=standard, type=number}, line_number={analyzer=standard, type=string}, text_entry={analyzer=standard, type=text}, speaker={analyzer=standard, type=string}, line_id={analyzer=standard, type=integer}}}]"}],"type":"mapper_parsing_exception","reason":"Failed to parse mapping [_doc]: Root mapping definition has unsupported parameters: [shakespeares : {_source={enabled=true}, properties={play_name={analyzer=standard, type=string}, speech_number={analyzer=standard, type=number}, line_number={analyzer=standard, type=string}, text_entry={analyzer=standard, type=text}, speaker={analyzer=standard, type=string}, line_id={analyzer=standard, type=integer}}}]","caused_by":{"type":"mapper_parsing_exception","reason":"Root mapping definition has unsupported parameters: [shakespeares : {_source={enabled=true}, properties={play_name={analyzer=standard, type=string}, speech_number={analyzer=standard, type=number}, line_number={analyzer=standard, type=string}, text_entry={analyzer=standard, type=text}, speaker={analyzer=standard, type=string}, line_id={analyzer=standard, type=integer}}}]"}},"status":400}
I created model /app/Shakespeare.php :

<?php

namespace App;

use DB;
use Illuminate\Database\Eloquent\Model;
use App\library\MyFuncsClass;

use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Storage;
use Illuminate\Validation\Rule;
use Elasticquent\ElasticquentTrait;

class Shakespeare extends Model
{
    use ElasticquentTrait;
    protected $table = 'shakespeares';
    protected $primaryKey = 'id';
    public $timestamps = false;

    protected $mappingProperties = array(
/*        'title' => array(
            'type' => 'string',
            'analyzer' => 'standard'
        )*/
        'line_id' => [
            'type' => 'integer',
            'analyzer' => 'standard'
        ],

        'play_name' => [
            'type' => 'string',
            'analyzer' => 'standard' // not_analyzed
        ],

        'speech_number' => [
            'type' => 'number',
            'analyzer' => 'standard'
        ],

        'line_number' => [
            'type' => 'string', // line_number??
            'analyzer' => 'standard'
        ],

        'speaker' => [
            'type' => 'string',
            'analyzer' => 'standard' // not_analyzed
        ],

        'text_entry' => [
            'type' => 'text',
            'analyzer' => 'standard'
        ],

    );

    protected $fillable = [
        'id', 'line_id', 'play_name', 'speech_number', 'line_number', 'speaker', 'text_entry', 'created_at', 'updated_at'
    ];

    function getIndexName()
    {
        return 'shakespeares_root';
    }

    public static function setESMapping()
    {
//        if (   Shakespeare::mappingExists() ) {
//        Shakespeare::deleteMapping();
//        }

        // Error pointing to line below !
        $ret= Shakespeare::createIndex(/*$shards = null, $replicas = null*/);
        \Log::info( '-1 setESMapping $ret ::' . print_r(  $ret, true  ) );

        $ret= Shakespeare::putMapping( true/*$ignoreConflicts = true*/);
        \Log::info( '-2 setESMapping $ret ::' . print_r(  $ret, true  ) );

        $ret= Shakespeare::addAllToIndex();
        \Log::info( '-3 setESMapping $ret ::' . print_r(  $ret, true  ) );

my config/elasticquent.php :

<?php

return array(
    'config' => [
        'hosts'     => ['localhost:9200'],
        'retries'   => 1,
    ],

    'default_index' => 'my_custom_index_name',
);

elasticsearch us running at the moment and I have in console :

 curl localhost:9200
{
  "name" : "athoe",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "e53SDZ6PTMyXhbeJ0Zx7TQ",
  "version" : {
    "number" : "7.7.0",
    "build_flavor" : "default",
    "build_type" : "deb",
    "build_hash" : "81a1e9eda8e6183f5237786246f6dced26a10eaf",
    "build_date" : "2020-05-12T02:01:37.602180Z",
    "build_snapshot" : false,
    "lucene_version" : "8.5.1",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

I tried to hide columns in $mappingProperties , leaving only sample

'title' => array(
            'type' => 'string',
            'analyzer' => 'standard'
        )

But I have the same error. How to fix it ?

elasticsearch : Version: 7.7.0 Thanks!

Smokietr commented 4 years ago

We are waiting for a solution. https://github.com/elasticquent/Elasticquent/issues/127

hrodriguez758 commented 4 years ago

I think the problems in this line $mapping['body'][$instance->getTypeName()] = $params;

in the elasticquent/elasticquent/src/ElasticquentTrait.php

The type name is not part of the body, the body should look like:

body: {
    "_source": {
        "enabled":true
    },
    "properties": { 
        "price": {"type":"integer"}
    }
}

Right now I'm mapping my fields correctly. using $mapping['body'] = $params;

vahidalvandi commented 2 years ago

i have same probleam

akmalsw17 commented 2 years ago

i have same problem

mhamzase commented 2 years ago

I have also same problem

hectorrodriguez773 commented 2 years ago

I'm still using my approach and works for me did you try with it? Event I created a patch in order to apply it after install my dependencies.

mhamzase commented 2 years ago

@hectorrodriguez773 which approach you are using please let me know?

hectorrodriguez773 commented 2 years ago

The problems in this line $mapping['body'][$instance->getTypeName()] = $params;

in the elasticquent/elasticquent/src/ElasticquentTrait.php

The type name is not part of the body, the body should look like:

body: {
    "_source": {
        "enabled":true
    },
    "properties": { 
        "price": {"type":"integer"}
    }
}

You have to use $mapping['body'] = $params;