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

Error on creating index #81

Closed
alireza2281 opened this issue Feb 5, 2022 · 7 comments
Closed

Error on creating index #81

alireza2281 opened this issue Feb 5, 2022 · 7 comments

Comments

@alireza2281
Copy link

Hello, after running sail php artisan elastic:create i'm getting this error

{"error":{"root_cause":[{"type":"parse_exception","reason":"key [settings] must be an object"}],"type":"parse_exception","reason":"key [settings] must be an object"},"status":400}

my explorer.php file content is:

<?php

declare(strict_types=1);

return [
    /*
     * There are different options for the connection. Since Explorer uses the Elasticsearch PHP SDK
     * under the hood, all the host configuration options of the SDK are applicable here. See
     * https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/configuration.html
     */
    'connection' => [
        'host' => 'es01',
        'port' => '9200',
        'scheme' => 'http',
    ],

    /**
     * An index may be defined on an Eloquent model or inline below. A more in depth explanation
     * of the mapping possibilities can be found in the documentation of Explorer's repository.
     */
    'indexes' => [
        \Modules\Contract\Entities\Contract::class,
        \Modules\Content\Entities\Blog::class
    ],

    /**
     * You may opt to keep the old indices after the alias is pointed to a new index.
     * A model is only using index aliases if it implements the Aliased interface.
     */
    'prune_old_aliases' => true,
];

and i have implemented Explorer "mappableAs" for both my models

@Jeroen-G
Copy link
Owner

Jeroen-G commented Feb 6, 2022

Can you show me the mappableAs implementations?

@alireza2281
Copy link
Author

Sure

The mappableAs of Blog model:

public function mappableAs(): array
    {
        return [
            'id' => 'keyword',
            'title' => 'text',
            'category' => 'text',
            'tag' => 'text',
            'excerpt' => 'text',
            'author' => 'text',
            'slug' => 'text',
            'created_at' => 'date',
        ];
    }

and mappableAs of contract mode:

public function mappableAs(): array
    {
        return [
            'id' => 'keyword',
            'name' => 'text',
            'description' => 'text',
            'created_at' => 'date',
        ];
    }

@Jeroen-G
Copy link
Owner

Jeroen-G commented Feb 7, 2022

Hmm, that seems ok. What versions of Laravel, Laravel Scout and Explorer are you running? I will have to see if I can reproduce this.

@alireza2281
Copy link
Author

OK,

Laravel: 8.77.1 , Laravel Scout: 9.4.2, Explorer: 2.5

by the way i'm using Laravel sail for development and docker-compose.yml elastik part is like this:

es01:
      image: docker.elastic.co/elasticsearch/elasticsearch:7.9.3
      container_name: es01
      environment:
        - node.name=es01
        - cluster.name=es-docker-cluster
        - discovery.type=single-node
        - bootstrap.memory_lock=true
        - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
      ulimits:
        memlock:
          soft: -1
          hard: -1
      volumes:
        - data01:/usr/share/elasticsearch/data
      ports:
        - 9200:9200
      networks:
        - sail
kib01:
    image: docker.elastic.co/kibana/kibana:7.9.3
    container_name: kib01
    ports:
      - 5601:5601
    environment:
      ELASTICSEARCH_URL: http://es01:9200
      ELASTICSEARCH_HOSTS: http://es01:9200
    networks:
      - sail

and if it's necessary i'm using Laravel-Modules and these two models are in separate modules

@Jeroen-G
Copy link
Owner

Jeroen-G commented Feb 7, 2022

Thanks, it looks the same as in the https://github.com/Jeroen-G/explorer-demo project

@Jeroen-G
Copy link
Owner

Jeroen-G commented Feb 9, 2022

Ok, this is indeed a bug in 2.5 when a model does not have the IndexSettings interface implemented. I'll try to fix it as soon as I find the time!

@Jeroen-G
Copy link
Owner

Jeroen-G commented Feb 9, 2022

Fixed in 2.5.1. Thanks for reporting!

@Jeroen-G Jeroen-G closed this as completed Feb 9, 2022
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