Skip to content

Commit

Permalink
feat(ES7): Remove type name from mapping configuration
Browse files Browse the repository at this point in the history
In ES7, specifying a mapping type name will no longer be allowed. ES6
can emulate this behavior by setting the `include_type_name` parameter
to `false` when creating and fetching mappings.

This PR sets that parameter so that our mapping format is compatible
with ES6, while using the ES7 preferred format.

In the future, when we wish to drop support for ES6, we'll only have to
stop using the `include_type_name` configuration option.

Connects pelias/pelias#831
  • Loading branch information
orangejulius committed Jan 8, 2020
1 parent 15e1e48 commit c887f26
Show file tree
Hide file tree
Showing 6 changed files with 566 additions and 579 deletions.
12 changes: 6 additions & 6 deletions integration/dynamic_templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ function nameAssertion( analyzer, common ){

suite.client.indices.getMapping({
index: suite.props.index,
type: _type
include_type_name: false
}, (err, res) => {

const properties = res[suite.props.index].mappings[_type].properties;
const properties = res[suite.props.index].mappings.properties;
t.equal( properties.name.dynamic, 'true' );

const nameProperties = properties.name.properties;
Expand Down Expand Up @@ -89,10 +89,10 @@ function phraseAssertion( analyzer, common ){

suite.client.indices.getMapping({
index: suite.props.index,
type: _type
include_type_name: false
}, ( err, res ) => {

const properties = res[suite.props.index].mappings[_type].properties;
const properties = res[suite.props.index].mappings.properties;
t.equal( properties.phrase.dynamic, 'true' );

const phraseProperties = properties.phrase.properties;
Expand Down Expand Up @@ -127,10 +127,10 @@ function addendumAssertion( namespace, value, common ){
suite.assert( done => {
suite.client.indices.getMapping({
index: suite.props.index,
type: _type
include_type_name: false,
}, ( err, res ) => {

const properties = res[suite.props.index].mappings[_type].properties;
const properties = res[suite.props.index].mappings.properties;
t.equal( properties.addendum.dynamic, 'true' );

const addendumProperties = properties.addendum.properties;
Expand Down
3 changes: 3 additions & 0 deletions integration/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ const common = {
},
create: {
schema: schema,
create: {
include_type_name: false
}
},
summaryMap: (res) => {
return res.hits.hits.map(h => {
Expand Down
6 changes: 1 addition & 5 deletions schema.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
const config = require('pelias-config').generate();

const schema = {
settings: require('./settings')(),
mappings: {
[config.schema.typeName]: require('./mappings/document'),
}
mappings: require('./mappings/document'),
};

module.exports = schema;
6 changes: 5 additions & 1 deletion scripts/create_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ try {
cli.header("create index");

const indexName = config.schema.indexName;
const req = { index: indexName, body: schema };
const req = {
index: indexName,
body: schema
include_type_name: false
};

client.indices.create(req, (err, res) => {
if (err) {
Expand Down
30 changes: 8 additions & 22 deletions test/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,17 @@ module.exports.tests.compile = function(test, common) {
// the api codebase against an index without admin data
module.exports.tests.indices = function(test, common) {
test('explicitly specify some admin indices and their analyzer', function(t) {
const _type = config.schema.typeName;
t.equal(typeof schema.mappings[_type], 'object', 'mappings present');
t.equal(schema.mappings[_type].dynamic_templates[0].nameGram.mapping.analyzer, 'peliasIndexOneEdgeGram');
t.equal(typeof schema.mappings, 'object', 'mappings present');
t.equal(schema.mappings.dynamic_templates[0].nameGram.mapping.analyzer, 'peliasIndexOneEdgeGram');
t.end();
});
};

// some 'admin' types allow single edgeNGrams and so have a different dynamic_template
module.exports.tests.dynamic_templates = function(test, common) {
test('dynamic_templates: nameGram', function(t) {
const _type = config.schema.typeName;
t.equal(typeof schema.mappings[_type].dynamic_templates[0].nameGram, 'object', 'nameGram template specified');
var template = schema.mappings[_type].dynamic_templates[0].nameGram;
t.equal(typeof schema.mappings.dynamic_templates[0].nameGram, 'object', 'nameGram template specified');
var template = schema.mappings.dynamic_templates[0].nameGram;
t.equal(template.path_match, 'name.*');
t.equal(template.match_mapping_type, 'string');
t.deepEqual(template.mapping, {
Expand All @@ -50,9 +48,8 @@ module.exports.tests.dynamic_templates = function(test, common) {
t.end();
});
test('dynamic_templates: phrase', function (t) {
const _type = config.schema.typeName;
t.equal(typeof schema.mappings[_type].dynamic_templates[1].phrase, 'object', 'phrase template specified');
var template = schema.mappings[_type].dynamic_templates[1].phrase;
t.equal(typeof schema.mappings.dynamic_templates[1].phrase, 'object', 'phrase template specified');
var template = schema.mappings.dynamic_templates[1].phrase;
t.equal(template.path_match, 'phrase.*');
t.equal(template.match_mapping_type, 'string');
t.deepEqual(template.mapping, {
Expand All @@ -63,9 +60,8 @@ module.exports.tests.dynamic_templates = function(test, common) {
t.end();
});
test('dynamic_templates: addendum', function (t) {
const _type = config.schema.typeName;
t.equal(typeof schema.mappings[_type].dynamic_templates[2].addendum, 'object', 'addendum template specified');
var template = schema.mappings[_type].dynamic_templates[2].addendum;
t.equal(typeof schema.mappings.dynamic_templates[2].addendum, 'object', 'addendum template specified');
var template = schema.mappings.dynamic_templates[2].addendum;
t.equal(template.path_match, 'addendum.*');
t.equal(template.match_mapping_type, 'string');
t.deepEqual(template.mapping, {
Expand Down Expand Up @@ -107,16 +103,6 @@ module.exports.tests.current_schema = function(test, common) {
// copy schema
var schemaCopy = JSON.parse( JSON.stringify( schema ) );

// the fixture contains a _type named 'doc'.
// this code allows the generated schema to match the fixture if the
// type name is defined named differently in pelias.json, the rest of
// the settings still apply verbatim.
const _type = config.schema.typeName;
if(_type && _type !== 'doc'){
schemaCopy.mappings.doc = schemaCopy.mappings[_type];
delete schemaCopy.mappings[_type];
}

// use the pelias config fixture instead of the local config
process.env.PELIAS_CONFIG = path.resolve( __dirname + '/fixtures/config.json' );
schemaCopy.settings = require('../settings')();
Expand Down
Loading

0 comments on commit c887f26

Please sign in to comment.