Skip to content

Commit

Permalink
Allow sample data set to install multiple indices (#23230)
Browse files Browse the repository at this point in the history
* Allow sample data set to install multiple indices

* create insertDataIntoIndex function to better encapsulate bulk insert

* move everything under bulk insert

* add comment in createIndexName
  • Loading branch information
nreese authored Sep 19, 2018
1 parent 2e5d3ec commit 0092278
Show file tree
Hide file tree
Showing 14 changed files with 535 additions and 394 deletions.
29 changes: 21 additions & 8 deletions src/server/sample_data/data_set_schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@

import Joi from 'joi';

export const dataSetSchema = {
const dataIndexSchema = Joi.object({
id: Joi.string().regex(/^[a-zA-Z0-9-]+$/).required(),
name: Joi.string().required(),
description: Joi.string().required(),
previewImagePath: Joi.string().required(),
overviewDashboard: Joi.string().required(), // saved object id of main dashboard for sample data set
defaultIndex: Joi.string().required(), // saved object id of default index-pattern for sample data set
dataPath: Joi.string().required(), // path to newline delimented JSON file containing data relative to KIBANA_HOME
fields: Joi.object().required(), // Object defining Elasticsearch field mappings (contents of index.mappings.type.properties)

// path to newline delimented JSON file containing data relative to KIBANA_HOME
dataPath: Joi.string().required(),

// Object defining Elasticsearch field mappings (contents of index.mappings.type.properties)
fields: Joi.object().required(),

// times fields that will be updated relative to now when data is installed
timeFields: Joi.array().items(Joi.string()).required(),
Expand All @@ -43,8 +42,22 @@ export const dataSetSchema = {
// Set to true to move timestamp to current week, preserving day of week and time of day
// Relative distance from timestamp to currentTimeMarker will not remain the same
preserveDayOfWeekTimeOfDay: Joi.boolean().default(false),
});

export const sampleDataSchema = {
id: Joi.string().regex(/^[a-zA-Z0-9-]+$/).required(),
name: Joi.string().required(),
description: Joi.string().required(),
previewImagePath: Joi.string().required(),

// saved object id of main dashboard for sample data set
overviewDashboard: Joi.string().required(),

// saved object id of default index-pattern for sample data set
defaultIndex: Joi.string().required(),

// Kibana saved objects (index patter, visualizations, dashboard, ...)
// Should provide a nice demo of Kibana's functionality with the sample data set
savedObjects: Joi.array().items(Joi.object()).required(),
dataIndices: Joi.array().items(dataIndexSchema).required(),
};
105 changes: 105 additions & 0 deletions src/server/sample_data/data_sets/flights/field_mappings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

/* eslint max-len: 0 */
/* eslint quotes: 0 */

export const fieldMappings = {
timestamp: {
type: 'date'
},
dayOfWeek: {
type: 'integer'
},
Carrier: {
type: 'keyword'
},
FlightNum: {
type: 'keyword'
},
Origin: {
type: 'keyword'
},
OriginAirportID: {
type: 'keyword'
},
OriginCityName: {
type: 'keyword'
},
OriginRegion: {
type: 'keyword'
},
OriginCountry: {
type: 'keyword'
},
OriginLocation: {
type: 'geo_point'
},
Dest: {
type: 'keyword'
},
DestAirportID: {
type: 'keyword'
},
DestCityName: {
type: 'keyword'
},
DestRegion: {
type: 'keyword'
},
DestCountry: {
type: 'keyword'
},
DestLocation: {
type: 'geo_point'
},
AvgTicketPrice: {
type: 'float'
},
OriginWeather: {
type: 'keyword'
},
DestWeather: {
type: 'keyword'
},
Cancelled: {
type: 'boolean'
},
DistanceMiles: {
type: 'float'
},
DistanceKilometers: {
type: 'float'
},
FlightDelayMin: {
type: 'integer'
},
FlightDelay: {
type: 'boolean'
},
FlightDelayType: {
type: 'keyword'
},
FlightTimeMin: {
type: 'float'
},
FlightTimeHour: {
type: 'keyword'
}
};
98 changes: 11 additions & 87 deletions src/server/sample_data/data_sets/flights/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import path from 'path';
import { savedObjects } from './saved_objects';
import { fieldMappings } from './field_mappings';

export function flightsSpecProvider() {
return {
Expand All @@ -28,93 +29,16 @@ export function flightsSpecProvider() {
previewImagePath: '/plugins/kibana/home/sample_data_resources/flights/dashboard.png',
overviewDashboard: '7adfa750-4c81-11e8-b3d7-01146121b73d',
defaultIndex: 'd3d7af60-4c81-11e8-b3d7-01146121b73d',
dataPath: path.join(__dirname, './flights.json.gz'),
fields: {
timestamp: {
type: 'date'
},
dayOfWeek: {
type: 'integer'
},
Carrier: {
type: 'keyword'
},
FlightNum: {
type: 'keyword'
},
Origin: {
type: 'keyword'
},
OriginAirportID: {
type: 'keyword'
},
OriginCityName: {
type: 'keyword'
},
OriginRegion: {
type: 'keyword'
},
OriginCountry: {
type: 'keyword'
},
OriginLocation: {
type: 'geo_point'
},
Dest: {
type: 'keyword'
},
DestAirportID: {
type: 'keyword'
},
DestCityName: {
type: 'keyword'
},
DestRegion: {
type: 'keyword'
},
DestCountry: {
type: 'keyword'
},
DestLocation: {
type: 'geo_point'
},
AvgTicketPrice: {
type: 'float'
},
OriginWeather: {
type: 'keyword'
},
DestWeather: {
type: 'keyword'
},
Cancelled: {
type: 'boolean'
},
DistanceMiles: {
type: 'float'
},
DistanceKilometers: {
type: 'float'
},
FlightDelayMin: {
type: 'integer'
},
FlightDelay: {
type: 'boolean'
},
FlightDelayType: {
type: 'keyword'
},
FlightTimeMin: {
type: 'float'
},
FlightTimeHour: {
type: 'keyword'
}
},
timeFields: ['timestamp'],
currentTimeMarker: '2018-01-09T00:00:00',
preserveDayOfWeekTimeOfDay: true,
savedObjects: savedObjects,
dataIndices: [
{
id: 'flights',
dataPath: path.join(__dirname, './flights.json.gz'),
fields: fieldMappings,
timeFields: ['timestamp'],
currentTimeMarker: '2018-01-09T00:00:00',
preserveDayOfWeekTimeOfDay: true,
}
]
};
}
Loading

0 comments on commit 0092278

Please sign in to comment.