[英]Elasticsearch template not creating new index in elasticsearch 1.7
我創建了一個索引模板並將其插入到我的本地 elasticsearch 存儲中。 使用以下命令:
curl -XPUT localhost:9200/_template/media_template -d ' { "template" : "media_*", "mappings" : { "properties": { "media-type": { "type": "string" } } } }
我已經安裝了 Elasticsearch-head,可以進入 Info>Templates 並看到我的模板確實已創建。 我假設一旦我有了模板,我就可以將名稱插入到任何索引中,該索引的名稱適合media_*的正則表達式,即使該索引尚不存在。 我希望能夠使用索引模板自動創建索引。
當我嘗試將記錄插入到尚未創建但它是media_*的有效正則表達式的索引中時,出現錯誤。 下面是我調用的插入語句,然后是錯誤。
$ curl -XPOST 'http://localhost:9200/media_2016_03_25/1' -d ' { "media-type" : "audio" } '
錯誤:
{ "error": "MapperParsingException[mapping [properties]]; nested: MapperParsingException[Root type mapping not empty after parsing! Remaining fields: [media-type : {type=string}]]; ", "status": 400 }
我究竟做錯了什么? 我誤解了索引模板嗎? 如果索引不存在並且符合模板規范,他們是否應該能夠自動創建索引?
我正在運行彈性搜索 1.7
在創建文檔時,您需要指定要應用映射的類型以及文檔的類型。
嘗試這個 :
curl -XPUT localhost:9200/_template/media_template -d '
{
"template" : "media_*",
"mappings" : {
"my-document-type" : {
"properties": {
"media-type": {
"type": "string"
}
}
}
}
}
然后創建您的文檔:
$ curl -XPOST 'http://localhost:9200/media_2016_03_25/my-document-type/1' -d '
{
"media-type" : "audio"
}
'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.