2016-05-12 57 views
1

我使用創建在ES動態映射:默認值

{ 
    "template": "infobox*", 
    "mappings": { 
    "_default_": { 
     "dynamic_templates": [ 
     { 
      "string_fields": { 
      "match": "*", 
      "match_mapping_type": "string", 
      "mapping": { 
       "type": "string", 
       "index": "analyzed", 
       "analyzer": "my_completion_analyzer", 
       "fielddata": { 
       "format": "disabled" 
       }, 
       "fields": { 
       "raw": { 
        "type": "string", 
        "index": "not_analyzed", 
        "ignore_above": 256 
       } 
       } 
      } 
      } 
     } 
     ] 
    } 
    } 
} 

所以,每當I指數具有date字段(birthYear)的文檔時,它會自動創建的字段(birthYear)與date類型。所以,只要我沒有birthYear,我會發送一個空字符串'',然後產生一個異常mapper_parsing_exception, failed to parse [birthYear]

有什麼辦法可以處理嗎?我可以分配一個默認值嗎?

+0

是'birthYear'類型的日期? –

+0

是的......是...... – PythonEnthusiast

回答

0

你要麼添加ignore_malformed: true所有date字段或設置此全局:

只有date領域

"dynamic_templates": [ 
    { 
     "string_fields": { 
     "match": "*", 
     "match_mapping_type": "string", 
     "mapping": { 
      "type": "string", 
      "index": "analyzed", 
      "analyzer": "whitespace", 
      "fielddata": { 
      "format": "disabled" 
      }, 
      "fields": { 
      "raw": { 
       "type": "string", 
       "index": "not_analyzed", 
       "ignore_above": 256 
      } 
      } 
     } 
     } 
    }, 
    { 
     "date_fields": { 
     "match": "*", 
     "match_mapping_type": "date", 
     "mapping": { 
      "type": "date", 
      "ignore_malformed": true 
     } 
     } 
    } 
    ] 

全局設置

{ 
    "settings": { 
    "index.mapping.ignore_malformed": true 
    }, 
    "mappings": { 
    "_default_": { 
     "dynamic_templates": [ 
     { 
      "string_fields": { 
      "match": "*", 
      "match_mapping_type": "string", 
      "mapping": { 
       "type": "string", 
       "index": "analyzed", 
       "analyzer": "whitespace", 
       "fielddata": { 
       "format": "disabled" 
       }, 
       "fields": { 
       "raw": { 
        "type": "string", 
        "index": "not_analyzed", 
        "ignore_above": 256 
       } 
       } 
      } 
      } 
     } 
     ] 
    } 
    } 
}