【问题标题】:Cannot create mapping on elasticsearch无法在弹性搜索上创建映射
【发布时间】:2020-04-03 15:23:49
【问题描述】:

我想在 elasticsearch 上创建一个索引,并且我想创建一个映射。

我对映射的理解是,这是插入数据以定义字段类型之前的可选步骤。

索引创建:

curl -X PUT "localhost:9200/idx5"

映射创建:

curl -X PUT "localhost:9200/idx5/_mapping" -H 'Content-Type: application/json' -d'
{
    "properties": {
        "element_type": {
            "type": "keyword"
        }
    }
}
'

现在,我尝试在索引中插入数据时出现此错误

[type] => illegal_argument_exception
[reason] => Rejecting mapping update to [idx5] as the final mapping would have more than 1 type: [_doc, doc]

如果我不创建映射,我没有错误。

有什么想法吗?

谢谢

** 编辑 **

弹性搜索版本:6.2.4

** 编辑 **

这是我尝试插入数据的方式:

curl -X POST http://localhost:9200/idx5/doc/ -H 'Content-Type: application/json' -d'{
         "id" : "1234",
         "element_type": "TYPE1",
          "title" : "test"
     }
     '

【问题讨论】:

  • 你用的是哪个es版本?
  • 6.2.4 查看我的编辑
  • 谢谢,正在调查中
  • 我已经添加了我尝试插入数据的方式
  • 谢谢,你能用这个网址http://localhost:9200/idx5/_doc/添加数据吗

标签: elasticsearch elasticsearch-mapping


【解决方案1】:

由于您使用的是 Elasticsearch 版本 6.X,它在单个索引中不支持多个 type,默认情况下,如果您不指定它会创建 _doc 类型,正如您所做的那样'在创建索引时不指定,它将使用_doc 类型。

现在在索引而不是使用 _doc 时,您使用的是 doc,这意味着 Elasticsearch 认为您正在为索引使用另一个 type 名称,因为它不受支持 Elastic 抛出错误(甚至指定名称您的索引中的类型 ?,在这种情况下是 doc_doc)。

只需将索引文档请求中的 URL 替换为 http://localhost:9200/idx5/_doc/ 即可。

请阅读elastic doc for removal of type 以及什么版本有什么变化。并且具体到 Elastic 6.X

在 6.x 中创建的索引只允许每个索引使用单一类型。任何名字 可以用于类型,但只能有一个。首选 类型名称是 _doc,以便索引 API 具有与它们相同的路径 在 7.0 中有:PUT {index}/_doc/{id} 和 POST {index}/_doc

【讨论】:

  • 我怎样才能创建'doc'类型而不是'_doc'默认类型?
  • 仅在创建索引时,但请注意,它需要请求正文和 POST 方法
  • @Bob5421,请点击此链接elastic.co/guide/en/elasticsearch/reference/6.2/…,在这里您甚至可以复制您正在使用的curl 命令并将样本的type1 更改为您的doc 或任何类型名称你想用??
  • 我已经复制/粘贴了这个例子,它给了我这个错误:“”根映射定义有不受支持的参数:[type1:{properties={field1={type=text}}}]“”
猜你喜欢
  • 1970-01-01
  • 2016-06-20
  • 2020-10-09
  • 1970-01-01
  • 2017-06-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多