elastically icon indicating copy to clipboard operation
elastically copied to clipboard

[Chore] Mapping file not found

Open EOL-Fred opened this issue 1 year ago • 6 comments

Hi,

First, here is my configuration : Elastically 1.9.2 (tried with 1.9.0 and 1.9.1) Symfony 7.0.6 with PHP 8.2.21

I have a similar situation to Issue #187, when I try to create the index land-registry I have this error message :

In YamlProvider.php line 37:
Mapping file "/land-registry_mapping.yaml" not found. Please check your configuration.

This is the configuration files I use :

#config/packages/elastically.yaml
elastically:
    connections:
        default:
            client:
                host:                '%env(ELASTICSEARCH_HOST)%'
                # If you want to use the Symfony HttpClient (you MUST create this service)
                #transport:           'JoliCode\Elastically\Transport\HttpClientTransport'

            # Path to the mapping directory (in YAML)
            mapping_directory:       '%kernel.project_dir%/config/elasticsearch'

            # Size of the bulk sent to Elasticsearch (default to 100)
            bulk_size:               100

            # Mapping between an index name and a FQCN
            index_class_mapping:
                land-registry:     App\Model\Location\LandRegisty

            # Configuration for the serializer
            serializer:
                # Fill a static context
                context_mapping:
                    foo:                 bar

            # If you want to add a prefix for your index in elasticsearch (you can still call it by its base name everywhere!)
            # prefix: '%kernel.environment%'
#config/elasticsearch/land-registry_mapping.yaml
settings:
    number_of_replicas: 0
    number_of_shards: 1
    refresh_interval: 60s
mappings:
    dynamic: false
    properties:
        prefix:
            type: text
        section:
            type: text
        planNb:
            type: text
        sheet:
            type: text
        northBound:
            type: double
        southBound:
            type: double
        eastBound:
            type: double
        westBound:
            type: double
        type:
            type: keyword
        layer:
            type: keyword
        text:
            x:
                type: double
            y:
                type: double
            height:
                type: double
            text:
                type: text
            rotation:
                type: double
        polygon:
            type: geo_shape
        extended:
            IDU:
                type: text
            COAR:
                type: text
            INDP:
                type: text
            SUPF:
                type: text

EOL-Fred avatar Sep 04 '24 08:09 EOL-Fred

I has exactly the same problem of you.

My config is good :

image

When i use the debugger, i can see in Yaml Provider the configuration Directory is not set

image

SalvadorCardona avatar Nov 07 '24 15:11 SalvadorCardona

And When i try to surcharge YamlProvider with this config, my Service is never runned

image

SalvadorCardona avatar Nov 07 '24 15:11 SalvadorCardona

Are you using the provided service?

Can you show some code? Because it's very suspicious that the configurationDirectory is empty.

I just tried on a new project, and I cannot reproduce.

With the same config as in the README and you, this works:

<?php

namespace App\Controller;

use JoliCode\Elastically\IndexBuilder;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Attribute\Route;

class HomeController extends AbstractController
{
    #[Route('/', name: 'app_home')]
    public function index(IndexBuilder $builder): JsonResponse
    {
        $builder->createIndex('my-foobar-index');

        return $this->json([
            'message' => 'Welcome to your new controller!',
            'path' => 'src/Controller/HomeController.php',
        ]);
    }
}

But if you get the IndexBuilder in another way, it may break.

So I need to know how you used it :+1:

damienalexandre avatar Nov 13 '24 21:11 damienalexandre

Are you using the provided service?

Can you show some code? Because it's very suspicious that the configurationDirectory is empty.

I just tried on a new project, and I cannot reproduce.

With the same config as in the README and you, this works:

<?php

namespace App\Controller;

use JoliCode\Elastically\IndexBuilder;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Attribute\Route;

class HomeController extends AbstractController
{
    #[Route('/', name: 'app_home')]
    public function index(IndexBuilder $builder): JsonResponse
    {
        $builder->createIndex('my-foobar-index');

        return $this->json([
            'message' => 'Welcome to your new controller!',
            'path' => 'src/Controller/HomeController.php',
        ]);
    }
}

But if you get the IndexBuilder in another way, it may break.

So I need to know how you used it 👍

The problem, when this tutorial : https://jolicode.com/blog/elasticsearch-the-right-way-in-symfony

In this tutorial, i can see get the service by the client service like this :

$indexBuilder = $this->client->getIndexBuilder(); $newIndex = $indexBuilder->createIndex('post'); $indexer = $this->client->getIndexer();

i has resolved this problem when i inject each service by autowiring like this :

image

SalvadorCardona avatar Nov 14 '24 07:11 SalvadorCardona

Oh ok I see. The library changed a lot since the tutorial, we need to make some changes on it.

Thanks for the feedback I'm leaving this issue open until the tutorial is fixed as well.

damienalexandre avatar Nov 14 '24 08:11 damienalexandre

Oh ok I see. The library changed a lot since the tutorial, we need to make some changes on it.

Thanks for the feedback I'm leaving this issue open until the tutorial is fixed as well.

Now, i has new problem why i has abandoned Elastically. I just return this problem.

I use the last version of Api Platform and has library conflict beetween Api Platform and Elasticaly.

But it's an other problem.

Good day for you 😁

SalvadorCardona avatar Nov 14 '24 08:11 SalvadorCardona

As the old way is not possible anymore with Elastically 2.0 I'm closing this issue.

The way to go it to use dependency injection, always 👍

Cheers

damienalexandre avatar Oct 20 '25 15:10 damienalexandre