Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Es5 compat #195

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions mappings/document.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
module.exports = function(config) {

var admin = require('./partial/admin');
var hash = require('./partial/hash');
var multiplier = require('./partial/multiplier');
var literal = require('./partial/literal');

var schema = {
return {
properties: {

// data partitioning
Expand Down Expand Up @@ -100,7 +102,7 @@ var schema = {
},

// geography
center_point: require('./partial/centroid'),
center_point: require('./partial/centroid')(config),
shape: require('./partial/shape'),
bounding_box: require('./partial/boundingbox'),

Expand Down Expand Up @@ -144,4 +146,4 @@ var schema = {
dynamic: 'true'
};

module.exports = schema;
};
27 changes: 19 additions & 8 deletions mappings/partial/centroid.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
module.exports = function(config) {

var es_version = config && config.esclient && config.esclient.apiVersion;

// @ref: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-geo-point-type.html
var schema = {
'type': 'geo_point',
var schema = { 'type': 'geo_point' };

// The enclosed options are required for es versions earlier than 5.x
// Using `!es_version || ` because right now recommended version is 2.3
// HACK: I want to use semver but check the following link:
// https://github.com/mojombo/semver/issues/237
// This lexicographical ordering should be fine until major version 10
if(!es_version || es_version < '5.0') {
/* `lat_lon` enabled since both the geo distance and bounding box filters can either be executed using in memory checks, or using the indexed lat lon values */
'lat_lon': true,
schema['lat_lon'] = true;

/* store geohashes (with prefixes) in order to facilitate the geohash_cell filter */
'geohash': true,
'geohash_prefix': true,
'geohash_precision': 18
};
schema['geohash'] = true;
schema['geohash_prefix'] = true;
schema['geohash_precision'] = 18;
}

module.exports = schema;
return schema;

};
6 changes: 4 additions & 2 deletions schema.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
var doc = require('./mappings/document');
var config = require('pelias-config').generate().export(),
settings = require('./settings')(config),
doc = require('./mappings/document')(config);

var schema = {
settings: require('./settings')(),
settings: settings,
mappings: {
/**
the _default_ mapping is applied to all new _type dynamically added after
Expand Down
5 changes: 1 addition & 4 deletions settings.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
var Mergeable = require('mergeable');
var peliasConfig = require('pelias-config');
var punctuation = require('./punctuation');
var street_suffix = require('./street_suffix');

var moduleDir = require('path').dirname("../");

function generate(){
var config = peliasConfig.generate().export();

function generate(config) {
// Default settings
var settings = {
"analysis": {
Expand Down
14 changes: 9 additions & 5 deletions test/compile.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
var path = require('path'),
schema = require('../'),
var path = require('path');

process.env.PELIAS_CONFIG = path.resolve( __dirname + '/fixtures/config.json' );

var schema = require('../'),
fixture = require('./fixtures/expected.json');

module.exports.tests = {};
Expand Down Expand Up @@ -58,9 +61,10 @@ module.exports.tests.current_schema = function(test, common) {
// copy schema
var schemaCopy = JSON.parse( JSON.stringify( schema ) );

// use the pelias config fixture instead of the local config
process.env.PELIAS_CONFIG = path.resolve( __dirname + '/fixtures/config.json' );
schemaCopy.settings = require('../settings')();
// use a different pelias config fixture with the same apiVersion
process.env.PELIAS_CONFIG = path.resolve( __dirname + '/fixtures/alt_config2.json' );
var config = require('pelias-config').generate().export();
schemaCopy.settings = require('../settings')(config);
delete process.env.PELIAS_CONFIG;

// code intentionally commented to allow quick debugging of expected.json
Expand Down
2 changes: 1 addition & 1 deletion test/document.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var schema = require('../mappings/document');
var schema = require('../mappings/document')();

module.exports.tests = {};

Expand Down
9 changes: 9 additions & 0 deletions test/fixtures/alt_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"elasticsearch": {
"settings": {
"index": {
"number_of_replicas": "999"
}
}
}
}
7 changes: 7 additions & 0 deletions test/fixtures/alt_config2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"imports": {
"whosonfirst": {
"datapath": "/path/to/whosonfirst"
}
}
}
10 changes: 1 addition & 9 deletions test/fixtures/config.json
Original file line number Diff line number Diff line change
@@ -1,9 +1 @@
{
"elasticsearch": {
"settings": {
"index": {
"number_of_replicas": "999"
}
}
}
}
{}
2 changes: 1 addition & 1 deletion test/fixtures/expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -1565,7 +1565,7 @@
}
},
"index": {
"number_of_replicas": "999",
"number_of_replicas": "0",
"number_of_shards": "1",
"refresh_interval": "1m"
}
Expand Down
14 changes: 13 additions & 1 deletion test/partial-centroid.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@

var schema = require('../mappings/partial/centroid');
var schema_cons = require('../mappings/partial/centroid'),
schema = schema_cons(),
schema5x = schema_cons({esclient:{apiVersion:'5.0'}});

module.exports.tests = {};

Expand Down Expand Up @@ -39,6 +41,16 @@ module.exports.tests.geohash = function(test, common) {
});
};

module.exports.tests.options_disabled_for_5_x = function(test, common) {
test('options disabled for elasticsearch 5.x', function(t) {
t.equal(schema5x.lat_lon, undefined, 'correctly unset');
t.equal(schema5x.geohash, undefined, 'correctly unset');
t.equal(schema5x.geohash_prefix, undefined, 'correctly unset');
t.equal(schema5x.geohash_precision, undefined, 'correctly unset');
t.end();
});
};

module.exports.all = function (tape, common) {

function test(name, testFunction) {
Expand Down
Loading