Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ export class ESSearchSource extends AbstractESSource {
}
}

async getTimeFields() {
async getDateFields() {
try {
const indexPattern = await this._getIndexPattern();
return indexPattern.fields.byType.date.map(field => {
return indexPattern.fields.getByType('date').map(field => {
return { name: field.name, label: field.name };
});
} catch (error) {
Expand Down Expand Up @@ -169,13 +169,28 @@ export class ESSearchSource extends AbstractESSource {
];
}

async _getFieldsExcludingTimeFields(fieldNames) {
const timeFieldNames = _.map(await this.getTimeFields(), 'name');
async _excludeDateFields(fieldNames) {
const dateFieldNames = _.map(await this.getDateFields(), 'name');
return fieldNames.filter(field => {
return !timeFieldNames.includes(field);
return !dateFieldNames.includes(field);
});
}

// Returns docvalue_fields array for the union of indexPattern's dateFields and request's field names.
async _getDateDocvalueFields(searchFields) {
const dateFieldNames = _.map(await this.getDateFields(), 'name');
return searchFields
.filter(fieldName => {
return dateFieldNames.includes(fieldName);
})
.map(fieldName => {
return {
field: fieldName,
format: 'epoch_millis'
};
});
}

async _getTopHits(layerName, searchFilters, registerCancelCallback) {
const {
topHitsSplitField,
Expand All @@ -184,7 +199,6 @@ export class ESSearchSource extends AbstractESSource {

const indexPattern = await this._getIndexPattern();
const geoField = await this._getGeoField();
const timeFields = await this.getTimeFields();

const scriptFields = {};
searchFilters.fieldNames.forEach(fieldName => {
Expand All @@ -202,26 +216,19 @@ export class ESSearchSource extends AbstractESSource {
const topHits = {
size: topHitsSize,
script_fields: scriptFields,
docvalue_fields: [],
docvalue_fields: await this._getDateDocvalueFields(searchFilters.fieldNames),
};
const nonDateFieldNames = await this._excludeDateFields(searchFilters.fieldNames);

const fieldNames = await this._getFieldsExcludingTimeFields(searchFilters.fieldNames);

timeFields.forEach(field => {
topHits.docvalue_fields.push({
field: field.name,
format: 'epoch_millis'
});
});
if (this._hasSort()) {
topHits.sort = this._buildEsSort();
}
if (geoField.type === ES_GEO_FIELD_TYPE.GEO_POINT) {
topHits._source = false;
topHits.docvalue_fields.push(...fieldNames);
topHits.docvalue_fields.push(...nonDateFieldNames);
} else {
topHits._source = {
includes: searchFilters.fieldNames
includes: nonDateFieldNames
};
}

Expand Down Expand Up @@ -268,24 +275,16 @@ export class ESSearchSource extends AbstractESSource {
// Performs Elasticsearch search request being careful to pull back only required fields to minimize response size
async _getSearchHits(layerName, searchFilters, registerCancelCallback) {
const initialSearchContext = {
docvalue_fields: []
docvalue_fields: await this._getDateDocvalueFields(searchFilters.fieldNames)
};
const geoField = await this._getGeoField();
const timeFields = await this.getTimeFields();
const fieldNames = await this._getFieldsExcludingTimeFields(searchFilters.fieldNames);
timeFields.forEach(field => {
initialSearchContext.docvalue_fields.push({
field: field.name,
format: 'epoch_millis'
});
});

let searchSource;
if (geoField.type === ES_GEO_FIELD_TYPE.GEO_POINT) {
// Request geo_point and style fields in docvalue_fields insted of _source
// 1) Returns geo_point in a consistent format regardless of how geo_point is stored in source
// 2) Setting _source to false so we avoid pulling back unneeded fields.
initialSearchContext.docvalue_fields.push(...fieldNames);
initialSearchContext.docvalue_fields.push(...(await this._excludeDateFields(searchFilters.fieldNames)));
searchSource = await this._makeSearchSource(searchFilters, ES_SIZE_LIMIT, initialSearchContext);
searchSource.setField('source', false); // do not need anything from _source
searchSource.setField('fields', searchFilters.fieldNames); // Setting "fields" filters out unused scripted fields
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ export class AbstractESSource extends AbstractVectorSource {
return null;
}

const fieldFromIndexPattern = indexPattern.fields.byName[rawFieldName];
const fieldFromIndexPattern = indexPattern.fields.getByName(rawFieldName);
if (!fieldFromIndexPattern) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class AbstractVectorSource extends AbstractSource {
return null;
}

async getTimeFields() {
async getDateFields() {
return [];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,10 +395,7 @@ export class VectorStyle extends AbstractStyle {

for (let j = 0; j < styleFields.length; j++) {
const { supportsFeatureState, isScaled, name, range, computedName } = styleFields[j];
//Date fields pulled from doc_values is an array
const value = Array.isArray(feature.properties[name])
? parseFloat(feature.properties[name][0])
: parseFloat(feature.properties[name]);
const value = parseFloat(feature.properties[name]);
let styleValue;
if (isScaled) {
if (isNaN(value) || !range) {//cannot scale
Expand Down
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/maps/public/layers/vector_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ export class VectorLayer extends AbstractLayer {
}

async getOrdinalFields() {
const timeFields = await this._source.getTimeFields();
const timeFields = await this._source.getDateFields();
const timeFieldOptions = timeFields.map(({ label, name }) => {
return {
label,
Expand Down