2016-05-12 112 views
1

我有一個索引,其映射的變化會非常大。考慮例如,我正在索引維基百科infobox每篇文章的數據。信息框中的數據不是結構化的,也不是統一的。因此,該數據可以是以下形式: -Elasticsearch - 在所有字段上設置默認分析器

Data1- { 
    'title': 'Sachin', 
    'Age': 41, 
    'Occupation': Cricketer 
} 

Data2- { 
    'title': 'India', 
    'Population': '23456987654', 
    'GDP': '23', 
    'NationalAnthem': 'Jan Gan Man' 
} 

由於所有的領域是不同的,我想在相關領域的應用領域完成,因此,我想對所有的領域應用分析儀。

索引時默認情況下,我如何在每個字段上應用分析器?

+0

在所有'string'字段中,我推定? –

+0

是的。只在字符串字段中。所有其他字段,如'int','double'都不應該被分析。 – PythonEnthusiast

回答

0

您需要爲您指數_default_模板,這樣,每當新的字段添加到它,那些string領域將採取的映射從_default_模板:

{ 
    "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 
       } 
       } 
      } 
      } 
     } 
     ] 
    } 
    } 
} 

或者,如果你的指數是不是每天的/每週一次,您可以使用_default_映射定義創建一次:

PUT /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 
       } 
       } 
      } 
      } 
     } 
     ] 
    } 
    } 
} 
+0

Som對大多數情況都適用,但是當我嘗試使用'birthYear'鍵索引另一個文檔時,它返回'mapper_parsing_exception,未能解析[birthYear]' – PythonEnthusiast

+0

因此,在檢查它實際創建的映射模式索引的第一個文檔的類型。當我用不同的鍵/字段索引另一個文檔時,它會引發錯誤。 – PythonEnthusiast

+0

爲什麼會發生這種情況? – PythonEnthusiast

相關問題