拒绝对 [] 的映射更新,因为最终映射将有 1 种以上的类型

dem*_*mas 7 elasticsearch

我已经使用显式映射创建索引:

PUT http://192.168.1.71:9200/items
{
  "mappings": {
    "properties": {
      "name": { 
        "type": "text",
        "fields": {
          "keyword": { 
            "type": "keyword"
          }
        }
      },
            "num": {
          "type": "long"
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

并尝试添加文档:

POST http://192.168.1.71:9200/items/1
{
  "num" : 1.898,
  "name" : "aaa"   
}
Run Code Online (Sandbox Code Playgroud)

但得到错误:

{
  "error": {
    "root_cause": [
      {
        "type": "illegal_argument_exception",
        "reason": "Rejecting mapping update to [items] as the final mapping would have more than 1 type: [_doc, 1]"
      }
    ],
    "type": "illegal_argument_exception",
    "reason": "Rejecting mapping update to [items] as the final mapping would have more than 1 type: [_doc, 1]"
  },
  "status": 400
}
Run Code Online (Sandbox Code Playgroud)

为什么以及如何安装它?

Pol*_*ton 7

您需要在idwhich之前指定文档类型_doc

POST http://192.168.1.71:9200/items/_doc/1
{
  "num" : 1.898,
  "name" : "aaa"   
}
Run Code Online (Sandbox Code Playgroud)