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

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

Open
PetroGromovo opened this issue May 27, 2020 · 8 comments

Comments

@PetroGromovo
Copy link

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
Copy link

Smokietr commented Jun 4, 2020

We are waiting for a solution.
#127

@hrodriguez758
Copy link

hrodriguez758 commented Jun 5, 2020

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
Copy link

i have same probleam

@akmalsw17
Copy link

i have same problem

@mhamzase
Copy link

mhamzase commented Sep 7, 2022

I have also same problem

@hectorrodriguez773
Copy link

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
Copy link

mhamzase commented Sep 8, 2022

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

@hectorrodriguez773
Copy link

  • Go to vendor/elasticquent/elasticquent/src/ElasticquentTrait.php
  • Replace all content for this ElasticquentTrait.txt (you can copy/paste)

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;

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

7 participants