2014-03-31 80 views
27

我试图更改索引的映射,但出现错误。以下是具体步骤我正创建索引为索引创建映射时出错

  • 通过Python脚本
  • 设置与此代码映射填充它创建索引:

    PUT /myidx/orderrow/_mapping 
    { 
        "orderrow": { 
         "properties": { 
          "item_code": { 
           "type": "string", 
           "index": "not_analyzed" 
          } 
         } 
        } 
    } 
    

这里的错误信息我得到:

{ 
    "error": "MergeMappingException[Merge failed with failures {[mapper [item_code] has different index values, mapper [item_code] has different `norms.enabled` values, mapper [item_code] has different tokenize values, mapper [item_code] has different index_analyzer]}]", 
    "status": 400 
} 

任何想法?

回答

30

因为您正在将数据索引到索引中,Elasticsearch会根据所加载的数据自动检测您的item_code字段的字段类型/映射。然后,当您尝试更新映射时,您会看到上面显示的错误。

我会建议在运行Python脚本来填充索引之前创建索引并应用映射。

PUT /myproj/ 

PUT /myproj/orderrow/_mapping 
{ 
    "orderrow": { 
     "properties": { 
      "item_code": { 
       "type": "string", 
       "index": "not_analyzed" 
      } 
     } 
    } 
    } 

或者,你可以强制冲突的映射到你的索引,使用如merging & conflicts section of the Put Mapping API Documentation定义的ignore_conflicts选项。但是,我不确定这将如何影响已经索引的文档。

+3

我不知道我可以先创建映射,这在我看来是一个更好的方法。我去做。谢谢! –

+0

我使用'ignore_conflicts'将现有属性的'store'值更改为'true',但尽管'acknoleged:true'没有改变。 – SerG

+1

'ignore_conflicts'已被删除https://github.com/elastic/elasticsearch/pull/11203 – BrunoLM

3

我有同样的问题,并解决它删除映射和创建它(警告:删除映射将删除所有文件(行)一个映射)

DELETE /myidx/orderrow/_mapping 

PUT /myidx/orderrow/_mapping -d ' 
... 
' 

在那之后,我不得不关闭并打开索引:

POST /myidx/_close 
POST /myidx/_open 
+7

注意:当您删除某个类型的映射时,还会删除索引中该类型的所有文档。请参阅:https://www.elastic.co/blog/changing-mapping-with-zero-downtime#_delete_the_mapping – paperclip

+0

您的评论应该在他的答案之前提出...... Aaa和我的所有文档现在都没有了。 –