0

我正在尝试从 Elastica 创建映射。

这是我使用映射参数创建索引的代码:

$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();

但我遇到以下错误:

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

我找不到如何在 Ruflin/Elastica 中传递“include_type_name = true”。

我所有的搜索都返回 CURL 中的示例..

非常感谢帮助我

4

2 回答 2

1

您似乎正在运行 ES7 并且include_type_name默认情况下为 false

您可以通过更改最后一行来防止该错误发生:

$mapping->send(['include_type_name' => true]);
于 2019-06-28T09:12:40.367 回答
0

这是工作 !!

这是我的配置: PHP 7.3.4 Symfony 4.3 Elasticsearch 7.0.1 composer 需要 elasticsearch/elasticsearch “dev-master” composer 需要 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]);
于 2019-06-28T11:49:18.063 回答