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

标签 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字段,但未做任何更改。

最佳答案

文件名是映射名。因此,对于/mappings/my_index/all_mappings.json,您应该拥有索引my_index和名为typeall_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/

    相关文章:

    installation - ubuntu-如何以该用户身份而不是sudo安装软件。收到错误 “Could not open lock file ”

    amazon-web-services - AWS Elastic Search中的部分字符串搜索以及多个单词

    elasticsearch - ElasticSearch中用户定义的术语向量

    php - 如何在ElasticSearch中的某些索引中搜索

    elasticsearch - 嵌入式Elasticsearch-第二次启动需要很长时间

    elasticsearch - SpringData 和 Elasticsearch - 使用 ignoreFields 时出现 java.lang.StackOverflowError

    mongodb - 同步elasticsearch和mongodb

    ruby - Logstash-输入文件插件以将数据保留在内存中

    ruby-on-rails - Heroku Bonsai 与 gem 'bonsai-elasticsearch-rails' 仍在寻找端口 9200

    elasticsearch - 将字符串字段转换为日期