【问题标题】:Elasticsearch template not creating new index in elasticsearch 1.7Elasticsearch 模板未在 elasticsearch 1.7 中创建新索引
【发布时间】:2016-03-26 04:14:27
【问题描述】:

我创建了一个索引模板并将其插入到我的本地 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

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    您需要指定要应用映射的类型以及创建文档时的类型。

    试试这个:

    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"
    }
    '
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-06
      • 2016-11-09
      • 1970-01-01
      • 2019-02-04
      • 1970-01-01
      • 2015-05-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多