创建索引映射时出错

Fra*_*ard 28 elasticsearch

我试图更改索引的映射,但收到错误.以下是我创建索引的步骤

  • 通过python脚本填充索引来创建索引
  • 使用以下代码设置映射:

    PUT /myidx/orderrow/_mapping
    {
        "orderrow": {
            "properties": {
                "item_code": {
                    "type": "string", 
                    "index": "not_analyzed"
                }
            }
        }
    }
    
    Run Code Online (Sandbox Code Playgroud)

这是我收到的错误消息:

{
   "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
}
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

Pai*_*ook 31

由于您首先将数据索引到索引中,因此Elasticsearch会item_code根据加载的数据自动检测字段的字段类型/映射.然后,当您尝试更新映射时,您将收到上面显示的错误.

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

PUT /myproj/

PUT /myproj/orderrow/_mapping
 {
    "orderrow": {
        "properties": {
            "item_code": {
                "type": "string", 
                 "index": "not_analyzed"
            }
         }
     }
  }
Run Code Online (Sandbox Code Playgroud)

或者,您可以使用Put Mapping API文档ignore_conflicts合并和冲突部分中定义的选项,将冲突映射强制转换为索引.但是,我不确定这将如何影响已编入索引的文档.

  • 我不知道我可以先创建映射,这在我看来是更好的方法.我去做.谢谢! (3认同)