我在CentOS上将Elasticsearch 1.5.2安装为服务。
我尝试使用PUT添加映射:
curl -XPUT $ES_HOST/my_index -d'
{
"mappings": {
"my_type": {
"properties": {
"field": {
"type": "nested"
}
}
}
}
}'
该请求可以正常工作,并创建具有正确映射的新索引。
我希望手动将映射存储在服务器上的配置文件中,而不是手动放置映射。为此,我创建了文件
/etc/elasticsearch/mappings/my_index/all_mappings.json
,其内容与先前的请求正文相同。之后,我尝试创建索引curl -XPUT $ES_HOST/my_index
,但发生错误{
"error": "MapperParsingException[mapping [all_mappings]]; nested:
MapperParsingException[Root type mapping not empty after parsing!
Remaining fields: [mappings : {my_type={properties={field={type=nested}}}}]]; ",
"status": 400
}
我试图删除config json中的
mappings
字段,但未做任何更改。
最佳答案
文件名是映射名。因此,对于/mappings/my_index/all_mappings.json
,您应该拥有索引my_index
和名为type
的all_mappings
。
此外,文件的内容应为:
{
"properties": {
"field": {
"type": "nested"
}
}
}
话虽如此,请执行以下操作:
my_type.json
文件夹/etc/elasticsearch/mappings/my_index
文件 {
"properties": {
"field": {
"type": "nested"
}
}
}
PUT /test_my_index
GET /test_my_index/_mapping
关于elasticsearch - 使用映射文件创建索引时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30639960/