0

I'm trying to create a mapping from Elastica.

Here is my code to create my index with params of mapping :

$elasticaClient = new ElasticaClient;
    $elasticaIndex = $elasticaClient->getIndex('products');

    $elasticaIndex->create(
        array(
            'settings' => array(
                'number_of_shards'   => 1,
                'number_of_replicas' => 0,
                'analysis' => array(
                    'filter' => array(
                        'french_elision' => array(
                            'type'          => 'elision',
                            'articles_case' => 'true',
                            'articles'      => array("l", "m", "t", "qu", "n", "s", "j", "d", "c", "jusqu", "quoiqu", "lorsqu", "puisqu"),
                        ),
                        'french_synonym' => array(
                            "type"        => "synonym",
                            "ignore_case" => true,
                            "expand"      => true,
                            "synonyms"    => []
                        ),
                        'french_stemmer' => array(
                            "type"     => "stemmer",
                            "language" => "light_french"
                        )
                    ),
                    'analyzer' => array(
                        'french_heavy' => array(
                            'type'      => 'custom',
                            'tokenizer' => 'icu_tokenizer',
                            'filter'    => array('french_elision', 'icu_folding', 'french_synonym', 'french_stemmer', 'asciifolding', 'lowercase')
                        ),
                        'french_light' => array(
                            'type'      => 'custom',
                            'tokenizer' => 'icu_tokenizer',
                            'filter'    => array('french_elision', 'icu_folding', 'lowercase', 'asciifolding')
                        )
                    )
                )
            )
        ),
        true
    );

    $elasticaType = $elasticaIndex->getType('product');

    $mapping = new $mapping = new ElasticaTypeMapping;
    $mapping->setType($elasticaType);
    $mapping->setParam('index_analyzer', 'french_heavy');
    $mapping->setParam('search_analyzer', 'french_light');

    $mapping->setProperties(
        array(
            'name' => array(
                'type' => 'string',
                'boost'    => 4
            ),
            'description' => array(
                'type' => 'string',
                'boost'    => 2
            ),
        )
    );

    $mapping->send();

But I'm having the following error:

Types can not be provided in put mapping requests, unless the include_type_name parameter is set to true.

I can't find how to pass "include_type_name = true" in Ruflin/Elastica.

All my searches return examples in CURL ..

Thank a lot to help me

Fabrice
  • 47
  • 10
  • You seem to be running ES7, am I right? Are you sure you have the correct version of Elastica that matches your ES version? – Val Jun 28 '19 at 09:11
  • Exacte, i've ES7, and Elastica 6.1 – Fabrice Jun 28 '19 at 10:04
  • You're supposed to use version 7 of Elastica: https://github.com/ruflin/Elastica#versions--dependencies – Val Jun 28 '19 at 11:14
  • Ok, thank, but every time I want install, composer install Elastica 6.1, not 7 But I've PHP 7.3.4 and Elasticsearch 7.0.1 – Fabrice Jun 28 '19 at 11:39
  • Indeed, the last released version is 6.1.1... Let me contact Nicolas Ruflin and ask him what's the plan. There might be a few roadblocks that prevent the release for ES7. – Val Jun 28 '19 at 11:42
  • So, i've install elasticsearch/elasticsearch in dev-master AND ruflin/elastica dev-master.. and it's WORK ! – Fabrice Jun 28 '19 at 11:47
  • Yes, indeed, if you install the latest version, it should be working! – Val Jun 28 '19 at 12:05
  • Elastica 7 is almost ready: https://twitter.com/ruflin/status/1189841431827034114 – Val Nov 01 '19 at 05:38

2 Answers2

1

You seem to be running ES7 and include_type_name is false by default.

You can prevent that error from occurring by changing the last line with this one:

$mapping->send(['include_type_name' => true]);
Val
  • 207,596
  • 13
  • 358
  • 360
  • IF I choose to keep include_type_name false by default, how do I do my mapping? Whenever I remove the type of my fields, I have an error: No type specified for field [name] – Fabrice Jun 28 '19 at 10:07
  • That's because you have a version mismatch between ES and Elastica. Upgrade to Elastica 7 and all will be good. – Val Jun 28 '19 at 11:15
  • I tried this, and I get: WD Elasticsearch: "include_type_name" is not a valid parameter. Allowed parameters are "allow_no_indices", "client", "custom", "expand_wildcards", "filter_path", "human", "ignore_conflicts", "ignore_unavailable", "master_timeout", "timeout", "update_all_types" I don't see any place to add this in the create() method, any ideas? – John Brandenburg Sep 30 '22 at 21:09
0

It's WORK !!

Here is my config : PHP 7.3.4 Symfony 4.3 Elasticsearch 7.0.1 composer require elasticsearch/elasticsearch "dev-master" composer require ruflin/elastica "dev-master"

$elasticaClient = new ElasticaClient;
    $elasticaIndex = $elasticaClient->getIndex('products');

    $elasticaType = $elasticaIndex->getType('product');

    $elasticaIndex->create(
        array(
            'settings' => array(
                'number_of_shards'   => 1,
                'number_of_replicas' => 0,
                'analysis' => array(
                    'filter' => array(
                        'french_elision' => array(
                            'type'          => 'elision',
                            'articles_case' => 'true',
                            'articles'      => array("l", "m", "t", "qu", "n", "s", "j", "d", "c", "jusqu", "quoiqu", "lorsqu", "puisqu"),
                        ),
                        'french_synonym' => array(
                            "type"        => "synonym",
                            "ignore_case" => true,
                            "expand"      => true,
                            "synonyms"    => []
                        ),
                        'french_stemmer' => array(
                            "type"     => "stemmer",
                            "language" => "light_french"
                        ),
                    ),
                    'analyzer' => array(
                        'french_heavy' => array(
                            'type'      => 'custom',
                            'tokenizer' => 'icu_tokenizer',
                            'filter'    => array('french_elision', 'icu_folding', 'french_synonym', 'french_stemmer', 'asciifolding', 'lowercase')
                        ),
                        'french_light' => array(
                            'type'      => 'custom',
                            'tokenizer' => 'icu_tokenizer',
                            'filter'    => array('french_elision', 'icu_folding', 'lowercase', 'asciifolding')
                        ),
                    )
                )
            )
        ),
        true
    );

    $mapping = new ElasticaTypeMapping;
    $mapping->setType($elasticaType);

    $mapping->setProperties(
        array(
            'name' => array(
                'type' => 'text',
                'analyzer' => 'french_heavy',
                'boost'    => 4
            ),
            'description' => array(
                'type' => 'text',
                'analyzer' => 'french_light',
                'boost'    => 2
            ),
        )
    );

    $mapping->send(['include_type_name' => true]);
Fabrice
  • 47
  • 10