2015-01-14 65 views
1

嘗試添加術語方面時,我遇到了術語將標記化爲單獨單詞的問題。例如,如果屬性(字段)Kind具有值medium kind of shirtlarge kind of shirt,則該術語變成:-,large,kind,of,shirt爲字段的所有子字段設置「索引」屬性

爲了解決這個問題,建議我將映射更改爲包含每個屬性字段的"index": "not_analyzed"。問題是,映射是動態生成的,比如 - :

"attributes": { 
    "properties": { 
     "kind": { 
     "type": "string" 
     }, 
     "color": { 
     "type": "string" 
     }, 
     "size": { 
     "type": "string" 
     } 
    } 
} 

簡單的設置裏面"attributes""not_analyzed"位不會做。有沒有辦法爲attributes字段中的每個子字段設置索引屬性?

+1

如果它是動態生成的,那麼你應該能夠爲它定義一個動態模板,你可以在其中指定'index'屬性。有關動態映射的詳細信息,請參閱:http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/custom-dynamic-mapping.html –

回答

1

感謝Andrei的評論,我能夠弄清楚如何應用這個設置。

我添加了一個dynamic_templates節到我的映射如下 - :

"dynamic_templates": [ 
    { 
     "string_template": { 
      "path_match": "attributes.*", 
      "match_mapping_type": "string", 
      "mapping": { 
       "type": "string", 
       "index": "not_analyzed" 
      } 
     } 
    } 
] 

這是卓有成效的,現在用"string"類型的每個子場都有自己的"index"設置爲"not_analyzed"。條款不再標記。