@@ -23,21 +23,31 @@ import { IIndexPattern } from '../..';
2323
2424describe ( 'SearchSource#normalizeSortRequest' , function ( ) {
2525 const scriptedField = {
26- name : 'script string ' ,
26+ name : 'script number ' ,
2727 type : 'number' ,
2828 scripted : true ,
2929 sortable : true ,
3030 script : 'foo' ,
3131 lang : 'painless' ,
3232 } ;
33+ const stringScriptedField = {
34+ ...scriptedField ,
35+ name : 'script string' ,
36+ type : 'string' ,
37+ } ;
38+ const booleanScriptedField = {
39+ ...scriptedField ,
40+ name : 'script boolean' ,
41+ type : 'boolean' ,
42+ } ;
3343 const murmurScriptedField = {
3444 ...scriptedField ,
3545 sortable : false ,
3646 name : 'murmur script' ,
3747 type : 'murmur3' ,
3848 } ;
3949 const indexPattern = {
40- fields : [ scriptedField , murmurScriptedField ] ,
50+ fields : [ scriptedField , stringScriptedField , booleanScriptedField , murmurScriptedField ] ,
4151 } as IIndexPattern ;
4252
4353 it ( 'should return an array' , function ( ) {
@@ -106,6 +116,54 @@ describe('SearchSource#normalizeSortRequest', function () {
106116 ] ) ;
107117 } ) ;
108118
119+ it ( 'should use script based sorting with string type' , function ( ) {
120+ const result = normalizeSortRequest (
121+ [
122+ {
123+ [ stringScriptedField . name ] : SortDirection . asc ,
124+ } ,
125+ ] ,
126+ indexPattern
127+ ) ;
128+
129+ expect ( result ) . toEqual ( [
130+ {
131+ _script : {
132+ script : {
133+ source : stringScriptedField . script ,
134+ lang : stringScriptedField . lang ,
135+ } ,
136+ type : 'string' ,
137+ order : SortDirection . asc ,
138+ } ,
139+ } ,
140+ ] ) ;
141+ } ) ;
142+
143+ it ( 'should use script based sorting with boolean type as string type' , function ( ) {
144+ const result = normalizeSortRequest (
145+ [
146+ {
147+ [ booleanScriptedField . name ] : SortDirection . asc ,
148+ } ,
149+ ] ,
150+ indexPattern
151+ ) ;
152+
153+ expect ( result ) . toEqual ( [
154+ {
155+ _script : {
156+ script : {
157+ source : booleanScriptedField . script ,
158+ lang : booleanScriptedField . lang ,
159+ } ,
160+ type : 'string' ,
161+ order : SortDirection . asc ,
162+ } ,
163+ } ,
164+ ] ) ;
165+ } ) ;
166+
109167 it ( 'should use script based sorting only on sortable types' , function ( ) {
110168 const result = normalizeSortRequest (
111169 [
0 commit comments