2016-11-21 108 views
1

到non_analyzed我有以下映射文檔類型:無法更改映射ElasticSearch

GET my_index/my_doctype/_mapping 
{ 
    "my_index": { 
    "mappings": { 
     "my_doctype": { 
     "properties": { 
      "@timestamp": { 
      "type": "date", 
      "format": "strict_date_optional_time||epoch_millis" 
      }, 
      "@version": { 
      "type": "string" 
      }, 
      "prod_id": { 
      "type": "string" 
      }, 
      "host": { 
      "type": "string" 
      }, 
      "message": { 
      "type": "string" 
      }, 
      "path": { 
      "type": "string" 
      }, 
      "img_path": { 
      "type": "string" 
      }, 
      "tags": { 
      "type": "string" 
      } 
     } 
     } 
    } 
    } 
} 

我試圖從analyzednon_analyzed所以我跑這個請求更改一些字段:

PUT my_index/_mapping/my_doctype 
{ 
    "properties": { 
    "prod_id": { 
     "type": "string", 
     "index": "not_analyzed" 
    }, 
    "img_path": { 
     "type": "string", 
     "index": "not_analyzed" 
    } 
    } 
} 

但我收到以下錯誤:

{ 
    "error": { 
     "root_cause": [ 
     { 
      "type": "illegal_argument_exception", 
      "reason": "Mapper for [img_path] conflicts with existing mapping in other types:\n[mapper [img_path] has different [index] values, mapper [img_path] has different [doc_values] values, cannot change from disabled to enabled, mapper [img_path] has different [analyzer], mapper [img_path] is used by multiple types. Set update_all_types to true to update [omit_norms] across all types., mapper [img_path] is used by multiple types. Set update_all_types to true to update [search_analyzer] across all types., mapper [img_path] is used by multiple types. Set update_all_types to true to update [search_quote_analyzer] across all types.]" 
     } 
     ], 
     "type": "illegal_argument_exception", 
     "reason": "Mapper for [img_path] conflicts with existing mapping in other types:\n[mapper [img_path] has different [index] values, mapper [img_path] has different [doc_values] values, cannot change from disabled to enabled, mapper [img_path] has different [analyzer], mapper [img_path] is used by multiple types. Set update_all_types to true to update [omit_norms] across all types., mapper [img_path] is used by multiple types. Set update_all_types to true to update [search_analyzer] across all types., mapper [img_path] is used by multiple types. Set update_all_types to true to update [search_quote_analyzer] across all types.]" 
    }, 
    "status": 400 
} 

何w將字段「prod_id」和「img_path」更改爲not_analyzed

回答

1

您無法更改現有字段的映射。有兩種解決方法:

  1. 您可以刪除索引,用適當的映射和重新索引重新創建數據
  2. 您可以創建一個not_analyzed子場和重新索引數據

第二種解決方案是這樣的:

PUT my_index/_mapping/my_doctype 
{ 
    "properties": { 
    "prod_id": { 
     "type": "string", 
     "fields": { 
     "raw": { 
      "type": "string", 
      "index": "not_analyzed" 
     } 
     } 
    }, 
    "img_path": { 
     "type": "string", 
     "fields": { 
     "raw": { 
      "type": "string", 
      "index": "not_analyzed" 
     } 
     } 
    } 
    } 
} 

然後你就可以使用prod_id.rawimg_path.raw你有reindexe後d你的數據。

+0

感謝您的回答,如何進行重新索引?我首先使用logstash進行索引。 – MedAli

+0

同樣,只需重新運行Logstash配置,它將填充新的/更新的索引 – Val

+0

好的,謝謝!會做 – MedAli