繁体   English   中英

Elasticsearch 模板未在 elasticsearch 1.7 中创建新索引

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM