I am new to Elastic search. Following the article https://www.elastic.co/guide/en/elasticsearch/reference/6.x/removal-of-types.html#_custom_type_field I made a index that could have multiple types using the type
keyword.
Here is my song index:
% curl -X GET "localhost:9200/_all/_mapping?pretty=true"
{
"song" : {
"mappings" : {
"_doc" : {
"properties" : {
"album" : {
"type" : "text"
},
"artist" : {
"type" : "text"
},
"date" : {
"type" : "date"
},
"deleted" : {
"type" : "boolean"
},
"filepath" : {
"type" : "text"
},
"genre" : {
"type" : "text"
},
"liked" : {
"type" : "boolean"
},
"playlist" : {
"type" : "text"
},
"title" : {
"type" : "text"
},
"trackNumber" : {
"type" : "text"
},
"type" : {
"type" : "keyword"
}
}
}
}
}
}
Use the elastic search node.js library, I tried inserting a artist with:
const { client } = require('../app/init-db');
const upsertArtist = (artist) => {
var doc = {
index: 'song',
type: 'artist',
body: {
artist: artist
}
};
return client.index(doc);
};
upsertArtist(tags[0].artist).catch(e => console.log(e))
But I get this error:
{ Error: [illegal_argument_exception] Rejecting mapping update to [song] as the final mapping would have more than 1 type: [_doc, artist]
at respond (/home/one/gitlab/echo-music-player/node_modules/elasticsearch/src/lib/transport.js:308:15)
at checkRespForFailure (/home/one/gitlab/echo-music-player/node_modules/elasticsearch/src/lib/transport.js:267:7)
at HttpConnector.<anonymous> (/home/one/gitlab/echo-music-player/node_modules/elasticsearch/src/lib/connectors/http.js:165:7)
at IncomingMessage.wrapper (/home/one/gitlab/echo-music-player/node_modules/elasticsearch/node_modules/lodash/lodash.js:4949:19)
at IncomingMessage.emit (events.js:165:20)
at endReadableNT (_stream_readable.js:1101:12)
at process._tickCallback (internal/process/next_tick.js:152:19)
status: 400,
displayName: 'BadRequest',
message: '[illegal_argument_exception] Rejecting mapping update to [song] as the final mapping would have more than 1 type: [_doc, artist]',
path: '/song/artist',
query: {},
body:
{ error:
{ root_cause: [Array],
type: 'illegal_argument_exception',
reason: 'Rejecting mapping update to [song] as the final mapping would have more than 1 type: [_doc, artist]' },
status: 400 },
statusCode: 400,
response: '{"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"Rejecting mapping update to [song] as the final mapping would have more than 1 type: [_doc, artist]"}],"type":"illegal_argument_exception","reason":"Rejecting mapping update to [song] as the final mapping would have more than 1 type: [_doc, artist]"},"status":400}',
toString: [Function],
toJSON: [Function] }
I followed the example on custom types for the new way of doing multiple types. Why is it saying there would be two types? As far as I see, I did it exactly like the example.