Skip to content

Commit

Permalink
feat(types): Remove _type field
Browse files Browse the repository at this point in the history
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.

Its possible that this will give us a performance benefit right away,
although it probably won't. It _will_ simplify our code a bit though!

Connects pelias/pelias#719
  • Loading branch information
orangejulius committed May 19, 2018
1 parent c8ee5e6 commit 06230a0
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 70 deletions.
23 changes: 2 additions & 21 deletions Document.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,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 );
}

Document.prototype.toJSON = function(){
Expand Down Expand Up @@ -101,8 +95,9 @@ Document.prototype.toESDocument = function() {

return {
_index: config.schema.indexName,
_type: this.getType(),
_id: this.getId(),
// From ES5 onward, the default mapping type name is '_doc'. However ES2 does not allow that, so use 'doc' for now
_type: 'doc',
data: doc
};
};
Expand All @@ -122,20 +117,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 ){

Expand Down
4 changes: 0 additions & 4 deletions test/Document.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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();
});
Expand Down
4 changes: 2 additions & 2 deletions test/document/toESDocument.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ module.exports.tests.toESDocument = function(test) {

var expected = {
_index: 'pelias',
_type: 'mylayer',
_id: 'myid',
_type: 'doc',
data: {
layer: 'mylayer',
name: {
Expand Down Expand Up @@ -94,8 +94,8 @@ module.exports.tests.toESDocument = function(test) {

var expected = {
_index: 'pelias',
_type: 'mylayer',
_id: 'myid',
_type: 'doc',
data: {
source: 'mysource',
layer: 'mylayer',
Expand Down
40 changes: 0 additions & 40 deletions test/document/type.js

This file was deleted.

1 change: 0 additions & 1 deletion test/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,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'),
Expand Down
2 changes: 0 additions & 2 deletions test/serialize/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -64,7 +63,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
Expand Down

0 comments on commit 06230a0

Please sign in to comment.