我正在尝试从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返回示例。
非常感谢我
答案 0 :(得分:0)
您似乎正在运行ES7和include_type_name
is false by default。
您可以通过更改最后一行来防止发生该错误:
$mapping->send(['include_type_name' => true]);
答案 1 :(得分:0)
这是工作!
这是我的配置: PHP 7.3.4 Symfony的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]);