首页 > 解决方案 > 使用json文件和curl命令将数据导入elasticsearch索引

问题描述

我正在尝试使用 curl 命令将位于 json 文件中的数据导入弹性搜索索引。

正在使用kibana如下方式创建索引

  PUT employees
  {
    "mappings" : {
        "properties":{
            "fields": {
                "properties": {
                    "id": {"type": "text"},
                    "nom": {"type": "text"},
                    "prenom": {"type": "text"},
                    "sexe": {"type": "text"},
                    "socials": {
                        "properties": {
                            "name": {"type": "text"},
                            "url": {"type": "text"} 
                        }
                    },
                }
            }   
        }
    }
}

我正在运行以下命令来导入数据

 curl -XPUT -H "Content-Type: application/json" localhost:9200/_bulk --data-binary @users.json

users.json文件包含如下表示的数据

 {"index": {"_index": "users", "_type": "user", "_id": 1}}
 {"fields": {"id": "5fe60ae52b40e53609c803ec","nom": "Jessica","prenom": "Herrera","aboutMe": "anim","socials": [{"name": "faacebook","url": "https://www.facebook.com/profile?id=5445546"},{"name": "linkedin","url": "https://www.linkedin.com/profile?id=5445546"}],"affiliations": [{"organisation": "ANARCO","equipe": "developpement","pays": "Russian Federation","dateD": "2013-06-03T00:00:00Z" ,"dateF": "2013-06-03T00:00:00Z" }]}}

这是我得到的错误

 "type":"illegal_argument_exception","reason":"Rejecting mapping update to [users] as the final mapping would have more than 1 type 

我已经阅读了很多资源,但仍然无法理解我所缺少的。

标签: elasticsearch

解决方案


"type":"illegal_argument_exception","re​​ason":"拒绝对 [users] 的映射更新,因为最终映射将有超过 1 种类型

由于Elasticsearch 6.x中的重大更改(其中不推荐使用映射类型),您会收到上述错误。

在 Elasticsearch 7.0.0 或更高版本中创建的索引不再接受 默认映射。在 6.x 中创建的索引将继续像以前在 Elasticsearch 6.x 中一样运行。类型在 7.0 的 API 中被弃用,对索引创建、放置映射、获取映射、放置模板、获取模板和获取字段映射 API 进行了重大更改。

您需要将 JSON 修改为 -

{"index": {"_index": "users", "_id": 1}}
{"fields": {"id": "5fe60ae52b40e53609c803ec","nom": "Jessica","prenom": "Herrera","aboutMe": "anim","socials": [{"name": "faacebook","url": "https://www.facebook.com/profile?id=5445546"},{"name": "linkedin","url": "https://www.linkedin.com/profile?id=5445546"}],"affiliations": [{"organisation": "ANARCO","equipe": "developpement","pays": "Russian Federation","dateD": "2013-06-03T00:00:00Z" ,"dateF": "2013-06-03T00:00:00Z" }]}}

推荐阅读