2014-03-31 87 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和我的所有文檔現在都沒有了。 –