From 89ed83a561439195b51bebe2e0ecc9447d36186a Mon Sep 17 00:00:00 2001 From: Julian Simioni Date: Tue, 1 May 2018 12:15:56 -0400 Subject: [PATCH] feat(types): Remove _type field Currently, we create numerous elasticsearch types, corresponding to different layers. All the types are identical, so they don't really serve any value. In Elasticsearch 6 [mapping types will go away](https://www.elastic.co/guide/en/elasticsearch/reference/6.2/removal-of-types.html). The sooner we can remove our minimal usage of types, the easier that transition will be. Connects https://github.com/pelias/pelias/issues/719 --- Document.js | 25 ++++------------------ test/Document.js | 4 ---- test/document/toESDocument.js | 6 +++--- test/document/type.js | 40 ----------------------------------- test/run.js | 1 - test/serialize/test.js | 2 -- 6 files changed, 7 insertions(+), 71 deletions(-) delete mode 100644 test/document/type.js diff --git a/Document.js b/Document.js index 4d55ec4..5fb5f01 100644 --- a/Document.js +++ b/Document.js @@ -49,12 +49,6 @@ function Document( source, layer, source_id ){ this.setLayer( layer ); this.setSourceId( source_id ); this.setId( source_id ); - - // set the elasticsearch '_type' property to be the same as $layer - // this may be removed/modified in the future if required but will mean - // that; for example; all 'address' data ends up in the same '_type', even - // if it comes from different sources. - this.setType( layer ); } // add a post-processing script which is run before generating the ES document @@ -142,8 +136,11 @@ Document.prototype.toESDocument = function() { return { _index: config.schema.indexName, - _type: this.getType(), _id: this.getGid(), + // In ES7, the only allowed document type will be `_doc`. + // However underscores are not allowed until ES6, so use `doc` for now + // see https://github.com/elastic/elasticsearch/pull/27816 + _type: 'doc', data: doc }; }; @@ -163,20 +160,6 @@ Document.prototype.getId = function(){ return this._meta.id; }; -// type -Document.prototype.setType = function( type ){ - - validate.type('string', type); - validate.truthy(type); - - this._meta.type = type; - return this; -}; - -Document.prototype.getType = function(){ - return this._meta.type; -}; - // source Document.prototype.setSource = function( source ){ diff --git a/test/Document.js b/test/Document.js index 26a61eb..0332b63 100644 --- a/test/Document.js +++ b/test/Document.js @@ -9,9 +9,6 @@ module.exports.tests.interface = function(test) { t.equal(typeof Document.prototype.getId, 'function', 'getId() is a function'); t.equal(typeof Document.prototype.setId, 'function', 'setId() is a function'); - t.equal(typeof Document.prototype.getType, 'function', 'getType() is a function'); - t.equal(typeof Document.prototype.setType, 'function', 'setType() is a function'); - t.equal(typeof Document.prototype.getSource, 'function', 'getSource() is a function'); t.equal(typeof Document.prototype.setSource, 'function', 'setSource() is a function'); @@ -42,7 +39,6 @@ module.exports.tests.constructor = function(test) { t.equal(doc.layer, 'mylayer', 'setter called'); t.equal(doc.source_id, 'myid', 'setter called'); t.equal(doc._meta.id, 'myid', 'setter called'); - t.equal(doc._meta.type, 'mylayer', 'setter called'); t.end(); }); diff --git a/test/document/toESDocument.js b/test/document/toESDocument.js index 9b0f127..8a3d1e1 100644 --- a/test/document/toESDocument.js +++ b/test/document/toESDocument.js @@ -49,7 +49,7 @@ module.exports.tests.toESDocument = function(test) { var expected = { _index: 'pelias', - _type: 'mylayer', + _type: 'doc', _id: 'mysource:mylayer:myid', data: { layer: 'mylayer', @@ -101,7 +101,7 @@ module.exports.tests.toESDocument = function(test) { var expected = { _index: 'pelias', - _type: 'mylayer', + _type: 'doc', _id: 'mysource:mylayer:myid', data: { source: 'mysource', @@ -155,7 +155,7 @@ module.exports.tests.toESDocument = function(test) { var expected = { _index: 'pelias', - _type: 'mylayer', + _type: 'doc', _id: 'mysource:mylayer:myid', data: { source: 'mysource', diff --git a/test/document/type.js b/test/document/type.js deleted file mode 100644 index d0bee91..0000000 --- a/test/document/type.js +++ /dev/null @@ -1,40 +0,0 @@ - -var Document = require('../../Document'); - -module.exports.tests = {}; - -module.exports.tests.getType = function(test) { - test('getType', function(t) { - var doc = new Document('mysource','mylayer','myid'); - doc._meta.type = 'foo'; - t.equal(doc.getType(), 'foo', 'getter works'); - t.end(); - }); -}; - -module.exports.tests.setType = function(test) { - test('setType', function(t) { - var doc = new Document('mysource','mylayer','myid'); - t.equal(doc._meta.type, 'mylayer', 'id set in constructor'); - t.equal(doc.setType('foo'), doc, 'chainable'); - t.equal(doc._meta.type, 'foo', 'id set'); - t.end(); - }); - test('setType - validate', function(t) { - var doc = new Document('mysource','mylayer','myid'); - t.throws( doc.setType.bind(doc,undefined), null, 'invalid type' ); - t.throws( doc.setType.bind(doc,''), null, 'invalid length' ); - t.end(); - }); -}; - -module.exports.all = function (tape, common) { - - function test(name, testFunction) { - return tape('type: ' + name, testFunction); - } - - for( var testCase in module.exports.tests ){ - module.exports.tests[testCase](test, common); - } -}; diff --git a/test/run.js b/test/run.js index 29c9bff..8c02749 100644 --- a/test/run.js +++ b/test/run.js @@ -15,7 +15,6 @@ var tests = [ require('./document/address.js'), require('./document/parent.js'), require('./document/polygon.js'), - require('./document/type.js'), require('./document/category.js'), require('./document/boundingbox.js'), require('./document/source.js'), diff --git a/test/serialize/test.js b/test/serialize/test.js index fa75215..bb104a0 100644 --- a/test/serialize/test.js +++ b/test/serialize/test.js @@ -19,7 +19,6 @@ module.exports.tests.minimal = function(test) { var s = serializeDeserialize( doc ); // document meta data - t.equal(doc.getMeta('type'), 'mylayer', 'correct _meta'); t.equal(doc.getMeta('id'), 'myid', 'correct _id'); // document body @@ -67,7 +66,6 @@ module.exports.tests.complete = function(test) { var s = serializeDeserialize( doc ); // document meta data - t.equal(doc.getMeta('type'), 'venue', 'correct _meta'); t.equal(doc.getMeta('id'), '1003', 'correct _id'); // document body