2016-08-24 31 views
1

動態映射,我有一個索引/鍵入test1的/所有這一切看起來如下:嵌套式

{ 
    "test1": { 
    "mappings": { 
     "all": { 
      "properties": { 
       "colors": { 
       "properties": { 
        "H": {"type": "double"}, 
        "S": {"type": "long"}, 
        "V": {"type": "long"}, 
        "color_percent": {"type": "long"} 
       } 
       }, 
       "file_name": { 
       "type": "string" 
       }, 
       "id": { 
       "type": "string" 
       }, 
       "no_of_colors": { 
       "type": "long" 
       } 
      } 
     } 
    } 
    } 
} 

我想使顏色的場嵌套的,我想以下幾點:

PUT /test1/all/_mapping 
{ 
    "mappings":{ 
      "all":{ 
       "properties": { 
        "file_name":{ 
         "type": "string", 
         "index": "not_analyzed" 
        }, 
        "id": { 
         "type": "string", 
         "index": "not_analyzed" 
        }, 
        "no_of_colors":{ 
        "type":"long", 
        "index": "not_analyzed" 
        }, 
        "colors":{ 
        "type":"nested", 
        "properties":{ 
         "H":{"type":"double"}, 
         "S":{"type":"long"}, 
         "V":{"type":"long"}, 
         "color_percent":{"type":"integer"} 
        } 
        } 
       }  
      } 
    } 
} 

,但我得到了以下錯誤:

{ 
"error": "MapperParsingException[Root type mapping not empty after parsing! 
Remaining fields: [mappings : {all={properties={file_name={type=string, index=not_analyzed}, id={type=string, index=not_analyzed}, no_of_colors={type=integer, index=not_analyzed}, colors={type=nested, properties={H={type=double}, S={type=long}, V={type=long}, color_percent={type=integer}}}}}}]]", 
"status": 400 
} 

有什麼建議?感謝幫助。

回答

1

就快,你只需要刪除mappings部分是這樣的:

PUT /test1/all/_mapping 
{ 
    "properties": { 
    "file_name": { 
     "type": "string", 
     "index": "not_analyzed" 
    }, 
    "id": { 
     "type": "string", 
     "index": "not_analyzed" 
    }, 
    "no_of_colors": { 
     "type": "long", 
     "index": "not_analyzed" 
    }, 
    "colors": { 
     "type": "nested", 
     "properties": { 
     "H": { 
      "type": "double" 
     }, 
     "S": { 
      "type": "long" 
     }, 
     "V": { 
      "type": "long" 
     }, 
     "color_percent": { 
      "type": "integer" 
     } 
     } 
    } 
    } 
} 

但是,請注意,這將不能工作,因爲你不能colors類型更改從objectnested和其他字符串字段從analyzed_not_analyzed。你需要刪除你的索引,並重新創建它

+0

確定工作。但正如你所說,我不得不刪除並重新創建。謝謝。 – venuktan