使用映射文件创建索引时出错

时间:2015-06-04 09:23:53

标签: elasticsearch

我在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字段,但没有任何更改。

1 个答案:

答案 0 :(得分:1)

文件名是映射名称。因此,对于/mappings/my_index/all_mappings.json,您应该将索引my_indextype称为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
相关问题