[Chore] Mapping file not found
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
I has exactly the same problem of you.
My config is good :
When i use the debugger, i can see in Yaml Provider the configuration Directory is not set
And When i try to surcharge YamlProvider with this config, my Service is never runned
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:
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 :
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.
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 😁
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