import data from into elasticsearch index using json file and curl command

Viewed 1307

I'm trying to import data located in a json file into an elasticsearch index using the curl command.

The index is being created using kibana as follow

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

I'm running the follwing command to import the data

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

the users.json file contains the data represented as follow

 {"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" }]}}

Here is the error I get

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

I've read many resources but still not able to understand what I'm missing.

1 Answers

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

You are getting the above error because of the breaking changes in Elasticsearch 6.x, in which the mapping types were deprecated.

Indices created in Elasticsearch 7.0.0 or later no longer accept a default mapping. Indices created in 6.x will continue to function as before in Elasticsearch 6.x. Types are deprecated in APIs in 7.0, with breaking changes to the index creation, put mapping, get mapping, put template, get template and get field mappings APIs.

You need to modify your JSON as -

{"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" }]}}
Related