[英]Elasticsearch template not creating new index in elasticsearch 1.7
I have created a index template and inserted it in my local elasticsearch store.我创建了一个索引模板并将其插入到我的本地 elasticsearch 存储中。 Using the following command:
使用以下命令:
curl -XPUT localhost:9200/_template/media_template -d ' { "template" : "media_*", "mappings" : { "properties": { "media-type": { "type": "string" } } } }
I have installed Elasticsearch-head and can go into the Info>Templates and see that my template was indeed created.我已经安装了 Elasticsearch-head,可以进入 Info>Templates 并看到我的模板确实已创建。 I am under the assumption that once I have a template then I can insert into any index with a name that fits within the regex of media_* even if that index does not yet exist.
我假设一旦我有了模板,我就可以将名称插入到任何索引中,该索引的名称适合media_*的正则表达式,即使该索引尚不存在。 I want to be able to auto create indexes using the index template.
我希望能够使用索引模板自动创建索引。
When I attempt to insert a record into an index that is not yet created, but is a valid regex of media_* , I get an error.当我尝试将记录插入到尚未创建但它是media_*的有效正则表达式的索引中时,出现错误。 Below is the insert statement that I call and after that is the error.
下面是我调用的插入语句,然后是错误。
$ curl -XPOST 'http://localhost:9200/media_2016_03_25/1' -d ' { "media-type" : "audio" } '
Error:错误:
{ "error": "MapperParsingException[mapping [properties]]; nested: MapperParsingException[Root type mapping not empty after parsing! Remaining fields: [media-type : {type=string}]]; ", "status": 400 }
What am I doing wrong?我究竟做错了什么? Am I misunderstanding index templates?
我误解了索引模板吗? Should they be able to auto create the index if it does not exist and is compliant with the template specification?
如果索引不存在并且符合模板规范,他们是否应该能够自动创建索引?
I am running elasticsearch 1.7我正在运行弹性搜索 1.7
you need to specify which type you are applying your mapping to and what's the type of your document when you are creating it.在创建文档时,您需要指定要应用映射的类型以及文档的类型。
Try this :尝试这个 :
curl -XPUT localhost:9200/_template/media_template -d '
{
"template" : "media_*",
"mappings" : {
"my-document-type" : {
"properties": {
"media-type": {
"type": "string"
}
}
}
}
}
Then this to create your document :然后创建您的文档:
$ 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.