弹性映射 include_type_name

Elastica Mapping include_type_name

我正在尝试从 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"。

我所有的搜索 return CURL 示例..

非常感谢帮助我

你似乎是 运行 ES7 和 include_type_name is false by default

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

$mapping->send(['include_type_name' => true]);

这是工作!!

这是我的配置: PHP7.3.4 交响乐 4.3 弹性搜索 7.0.1 作曲家需要 elasticsearch/elasticsearch "dev-master" 作曲家需要 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]);