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.

Connects pelias/pelias#719
  • Loading branch information
orangejulius committed Sep 5, 2019
1 parent 0e50c53 commit 89ed83a
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 71 deletions.
25 changes: 4 additions & 21 deletions Document.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
};
};
Expand All @@ -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 ){

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
6 changes: 3 additions & 3 deletions test/document/toESDocument.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
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 @@ -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'),
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 @@ -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
Expand Down

0 comments on commit 89ed83a

Please sign in to comment.