Default Mapping Setup


(Joe Grigg) #1

I have been trying to set up default mappings for a brand new index and I keep getting errors.

This is what I am doing

PUT /documents
{
  mappings": {
    "_default_: {
      "title": {"type": "string"},
      "author": {"type": "string"},
      "description": {"type": "string"},
      "tags": {"type": "string"},
      "country": {"type": "string"},
      "version": {"type": "double"},
      "revisions": {"type": "string"},
      "createdAt": {"type": "date"},
      "updatedAt": {"type": "date"},
      "fileType": {"type": "string"},
      "urlToFile": {"type": "string"},
      "archived": {"type": "boolean"},
      "archivedDate": {"type": "date"},
      "archivedReason": {"type": "string"}
    }
  }
}

And then the error that I am getting is:

{"error":"ElasticsearchParseException[failed to parse source for create index]; nested: JsonParseException[Illegal unquoted character ((CTRL-CHAR, code 10)): has to be escaped using backslash to be included in name\n at [Source: [B@75dfe5d5; line: 3, column: 17]]; ","status":400}

Does anyone have any ideas?


(Colin Goodheart-Smithe) #2

You are missing a " character after _default:


(Colin Goodheart-Smithe) #3

You are also missing a " before mappings:


(Joe Grigg) #4

Ah yeah that was silly.

However I have fixed that and still not having any luck.

I am still getting the same error :confused:


(Joe Grigg) #5

Never mind. But I do have a different error now :confused:

{"error":"MapperParsingException[mapping [_default_]]; nested: MapperParsingException[Root type mapping not empty after parsing! Remaining fields:   [archivedDate : {type=date}] [country : {type=string}] [urlToFile : {type=string}] [author : {type=string}] [description : {type=string}] [title : {type=string}] [version : {type=double}] [tags : {type=string}] [createdAt : {type=date}] [archived : {type=boolean}] [revisions : {type=string}] [fileType : {type=string}] [archivedReason : {type=string}] [updatedAt : {type=date}]]; ","status":400} 

Any ideas on this one? @colings86


(Colin Goodheart-Smithe) #6

You need to have a "properties":{} object under _default_ and put your fields in there. see https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-core-types.html for more information on setting mappings


(Joe Grigg) #7

Ah that has worked.

Thank you :smile:


(system) #8