@@ -163,6 +163,13 @@ export class ESSearchSource extends AbstractESSource {
163163 ] ;
164164 }
165165
166+ async _getFieldsExcludingTimeFields ( fieldNames ) {
167+ const timeFieldNames = _ . map ( await this . getTimeFields ( ) , 'name' ) ;
168+ return fieldNames . filter ( field => {
169+ return ! timeFieldNames . includes ( field ) ;
170+ } ) ;
171+ }
172+
166173 async _getTopHits ( layerName , searchFilters , registerCancelCallback ) {
167174 const {
168175 topHitsSplitField,
@@ -192,6 +199,8 @@ export class ESSearchSource extends AbstractESSource {
192199 docvalue_fields : [ ] ,
193200 } ;
194201
202+ const fieldNames = await this . _getFieldsExcludingTimeFields ( searchFilters . fieldNames ) ;
203+
195204 timeFields . forEach ( field => {
196205 topHits . docvalue_fields . push ( {
197206 field : field . name ,
@@ -203,7 +212,7 @@ export class ESSearchSource extends AbstractESSource {
203212 }
204213 if ( geoField . type === ES_GEO_FIELD_TYPE . GEO_POINT ) {
205214 topHits . _source = false ;
206- topHits . docvalue_fields . push ( ...searchFilters . fieldNames ) ;
215+ topHits . docvalue_fields . push ( ...fieldNames ) ;
207216 } else {
208217 topHits . _source = {
209218 includes : searchFilters . fieldNames
@@ -257,6 +266,7 @@ export class ESSearchSource extends AbstractESSource {
257266 } ;
258267 const geoField = await this . _getGeoField ( ) ;
259268 const timeFields = await this . getTimeFields ( ) ;
269+ const fieldNames = await this . _getFieldsExcludingTimeFields ( searchFilters . fieldNames ) ;
260270 timeFields . forEach ( field => {
261271 initialSearchContext . docvalue_fields . push ( {
262272 field : field . name ,
@@ -269,7 +279,7 @@ export class ESSearchSource extends AbstractESSource {
269279 // Request geo_point and style fields in docvalue_fields insted of _source
270280 // 1) Returns geo_point in a consistent format regardless of how geo_point is stored in source
271281 // 2) Setting _source to false so we avoid pulling back unneeded fields.
272- initialSearchContext . docvalue_fields . push ( ...searchFilters . fieldNames ) ;
282+ initialSearchContext . docvalue_fields . push ( ...fieldNames ) ;
273283 searchSource = await this . _makeSearchSource ( searchFilters , ES_SIZE_LIMIT , initialSearchContext ) ;
274284 searchSource . setField ( 'source' , false ) ; // do not need anything from _source
275285 searchSource . setField ( 'fields' , searchFilters . fieldNames ) ; // Setting "fields" filters out unused scripted fields
0 commit comments