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

I can't create index #214

Open
yannicknya opened this issue Mar 23, 2020 · 4 comments
Open

I can't create index #214

yannicknya opened this issue Mar 23, 2020 · 4 comments

Comments

@yannicknya
Copy link

yannicknya commented Mar 23, 2020

Laravel Framework 6.7.0
elasticquent/elasticquent: dev-master

Hi,
every time i try to create an index i get this error :
Elasticsearch/Common/Exceptions/BadRequest400Exception with message '{"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"Root mapping definition has unsupported parameters: [articles : {_source={enabled=true}, properties={title={analyzer=standard, type=string}}}]"}],"type":"mapper_parsing_exception","reason":"Failed to parse mapping [_doc]: Root mapping definition has unsupported parameters: [articles : {_source={enabled=true}, properties={title={analyzer=standard, type=string}}}]","caused_by":{"type":"mapper_parsing_exception","reason":"Root mapping definition has unsupported parameters: [articles : {_source={enabled=true}, properties={title={analyzer=standard, type=string}}}]"}},"status":400}'

i know this is because of my $mappingProperties, because when I remove it, the index is created well but with all the columns of my model => what I don't want. I would like to specify the fields and type them

My Aticles.php

`<?php
namespace App;
use Elasticquent\ElasticquentTrait;
use Illuminate\Database\Eloquent\Model;

class Article extends Model
{
use ElasticquentTrait;
protected $fillable = ['title', 'body', 'tags'];
protected $mappingProperties = array(
'title' => array(
'type' => 'string',
'analyzer' => 'standard'
)
);
}`
Can you help me ? thanks you so much

@seifEddineSalah
Copy link

Did you manage to get around this please ? I m facing the same problem.

@dendihandian
Copy link

dendihandian commented Apr 5, 2020

Same problem here. @timgws

my app\Book.php:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Elasticquent\ElasticquentTrait;

class Book extends Model
{
    use ElasticquentTrait;

    protected $guarded = [];

    /**
     * The elasticsearch settings.
     *
     * @var array
     */
    protected $indexSettings = [
        'analysis' => [
            'char_filter' => [
                'replace' => [
                    'type' => 'mapping',
                    'mappings' => [
                        '&=> and '
                    ],
                ],
            ],
            'filter' => [
                'word_delimiter' => [
                    'type' => 'word_delimiter',
                    'split_on_numerics' => false,
                    'split_on_case_change' => true,
                    'generate_word_parts' => true,
                    'generate_number_parts' => true,
                    'catenate_all' => true,
                    'preserve_original' => true,
                    'catenate_numbers' => true,
                ]
            ],
            'analyzer' => [
                'default' => [
                    'type' => 'custom',
                    'char_filter' => [
                        'html_strip',
                        'replace',
                    ],
                    'tokenizer' => 'whitespace',
                    'filter' => [
                        'lowercase',
                        'word_delimiter',
                    ],
                ],
            ],
        ],
    ];

    protected $mappingProperties = array(
        'title' => array(
            'type' => 'string',
            'analyzer' => 'standard'
        ),
    );

    function getIndexName()
    {
        return 'books';
    }

    function getTypeName()
    {
        return 'books';
    }
}

using tinker:

>>> \App\Book::createIndex($shards = null, $replicas = null);
Elasticsearch/Common/Exceptions/BadRequest400Exception with message '{"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"Root mapping definition has unsupported parameters:  [books : {_source={enabled=true}, properties={title={analyzer=standard, type=string}}}]"}],"type":"mapper_parsing_exception","reason":"Failed to parse mapping [_doc]: Root mapping definition has unsupported parameters:  [books : {_source={enabled=true}, properties={title={analyzer=standard, type=string}}}]","caused_by":{"type":"mapper_parsing_exception","reason":"Root mapping definition has unsupported parameters:  [books : {_source={enabled=true}, properties={title={analyzer=standard, type=string}}}]"}},"status":400}'

@yannicknya
Copy link
Author

yannicknya commented Apr 8, 2020

I created my index manually on elasticsearch

My model : dont forget getTypeName()

STEP 1


<?php

namespace App;
use Elasticquent\ElasticquentTrait;

use Illuminate\Database\Eloquent\Model;


class TransactionModel extends Model
{
	use ElasticquentTrait;
    protected $fillable = ["account_id", "amount" , "type_id" , "date" , "category_id" ,"state"];
    protected $table = 'transaction';
	public $timestamps = false; // car pas de champs update_at
   
	function getIndexName()
	{
		return 'transaction';
	}
		
		
	function getTypeName()
	{
		return '_doc';
	}
}

STEP 2

http://localhost:9200/transaction

PUT
{"settings":{"number_of_shards":1,"number_of_replicas":1},"mappings":{"properties":{"create_date":{"type":"date","format":"yyyy-MM-dd HH:mm:ss"},"write_date":{"type":"date","format":"yyyy-MM-dd HH:mm:ss"},"account_id":{"type":"integer"},"amount":{"type":"integer"},"date":{"type":"date","format":"yyyy-MM-dd"},"category_id":{"type":"integer"},"state":{"type":"integer"},"commentaire":{"type":"text"},"bank_id":{"type":"integer"}}}}

STEP 3
With TINKER

php artisan tinker 

TransactionModel::addAllToIndex();

this is how I managed to get around the issue

@dendihandian
Copy link

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

3 participants