2017-04-11 42 views
0

中的索引字段數。我默認看到,ES爲每個字段中的每個單詞創建索引。但在我的用例中,我只搜索兩個字段,所以我想以某種方式告訴ES不要爲文檔中的所有內容創建索引,但僅創建索引,僅指定映射中指定的字段。我可以限制Elasticsearch中新增的elasticsearch 5.3

所以這裏是我的映射

PUT /benefits 
    { 
    "mappings": { 
     "benefit": { 
     "_all": {"enabled": false}, 
      "properties": { 
      "subCategory": {"type": "text"}, 
      "description": {"type": "text"} 
     } 

     } 
    } 
} 

和我的文件看起來像這樣

{ 
"bpi" : "123456", 
"category" : "CAT1", 
"subCategory" : "Primary Care Physician Copay", 
"planName" : "MyPlan HMO Individual", 
"description" : "0 per office visit for Convenient Care & Minute Clinics Complete ABC Document", 
"categoryId" : 200.0, 
"desktop360Id" : 1001.0, 
"createTimeStamp" : "2017-02-21T22:00:12.000Z" 

}

所以我只能在"subCategory""description"(不"planName"或任何被搜索其他字段的文本),並創建索引/映射如上圖所示,但我仍然能夠搜索其他字段的文本好。例如,如果我從"planName"字段搜索「MyPlan」字段,則搜索起作用並調出此文檔。這是否意味着它爲所有字段中的所有單詞創建索引(除了那些'a',''類型)?我問這個問題是因爲我不想在我不需要的索引上花費內存。

有什麼建議嗎?

+1

你只需要在你的映射(與「_all」相同的級別)上加''dynamic「:」false「'。這將在對象級別執行此操作,但您也可以將它設置爲索引級別或模板中,以便爲所有索引進行設置。有關此信息[這裏](https://www.elastic.co/guide/en/elasticsearch/reference/current/dynamic-mapping.html) – Olivier

+0

謝謝奧利維爾。我想我明白了。看到我正在'回答您的問題' – JBone

回答

2

爲了排除索引中的其他字段,必須在映射中指定它們並將index屬性設置爲no值。這裏是一個例子

{ 
    "mappings": { 
     "benefit": { 
      "properties": { 
       "subCategory": { 
        "type": "string" 
       }, 
       "description": { 
        "type": "string" 
       }, 
       "planName": { 
        "type": "string", 
        "index": "no" 
       }, 
       "bpi": { 
        "type": "string", 
        "index": "no" 
       }, 
       "category": { 
        "type": "string", 
        "index": "no" 
       } 
      } 
     } 
    } 
} 
+0

這個工程。謝謝。 – JBone

+0

我有一個後續問題。我知道我應該發佈一個不同的問題,但我已經在此輸入了問題的背景,讓我問你這個問題。我如何將'subCategory'中的搜索結果放在'description'上,以增加權重?有什麼建議麼? – JBone

+0

我通過在創建索引時在這兩個字段中添加「boost」值來想出這一點。謝謝 – JBone