1- import { IRouter } from '../../../../src/core /server' ;
1+ import { IRouter , Logger } from 'kibana /server' ;
22import { schema } from '@kbn/config-schema' ;
33import { convertEsError } from "./handle_es_error" ;
44
5- export function defineRoutes ( router : IRouter ) {
5+ export function defineRoutes ( router : IRouter , logger : logger ) {
66 router . post (
77 {
88 path : '/api/analyze_api_ui/analyze' ,
@@ -11,10 +11,10 @@ export function defineRoutes(router: IRouter) {
1111 text : schema . string ( ) ,
1212 indexName : schema . maybe ( schema . nullable ( schema . string ( ) ) ) ,
1313 analyzer : schema . maybe ( schema . nullable ( schema . string ( ) ) ) ,
14- tokenizer : schema . maybe ( schema . oneOf ( [ schema . nullable ( schema . string ( ) ) , schema . object ( { } ) ] ) ) ,
14+ tokenizer : schema . maybe ( schema . oneOf ( [ schema . nullable ( schema . string ( ) ) , schema . object ( { } , { unknowns : 'allow' } ) ] ) ) ,
1515 field : schema . maybe ( schema . nullable ( schema . string ( ) ) ) ,
16- filters : schema . maybe ( schema . arrayOf ( schema . nullable ( schema . oneOf ( [ schema . string ( ) , schema . object ( { } ) ] ) ) ) ) ,
17- charfilters : schema . maybe ( schema . arrayOf ( schema . nullable ( schema . oneOf ( [ schema . string ( ) , schema . object ( { } ) ] ) ) ) )
16+ filters : schema . maybe ( schema . arrayOf ( schema . nullable ( schema . oneOf ( [ schema . string ( ) , schema . object ( { } , { unknowns : 'allow' } ) ] ) ) ) ) ,
17+ charfilters : schema . maybe ( schema . arrayOf ( schema . nullable ( schema . oneOf ( [ schema . string ( ) , schema . object ( { } , { unknowns : 'allow' } ) ] ) ) ) )
1818 } )
1919 }
2020 } ,
@@ -65,39 +65,43 @@ export function defineRoutes(router: IRouter) {
6565 } ;
6666 if ( request . body . indexName ) param . index = request . body . indexName ;
6767 const res = {
68- resultAnalyzers : [ ]
68+ body : {
69+ resultAnalyzers : [ ]
70+ }
6971 } ;
7072
7173 function getAnalyzerResult ( analyzer , id ) {
7274 return new Promise ( function ( resolve , reject ) {
7375 param . body . analyzer = analyzer ;
74- context . core . elasticsearch . client . asCurrentUser . indices . analyze ( param )
75- . then ( function ( response ) {
76- res . resultAnalyzers . push ( { analyzer : analyzer , id : id , tokens : response . tokens } ) ;
77- resolve ( res ) ;
78- } )
79- . catch ( error => {
76+ const results = context . core . elasticsearch . client . asCurrentUser . indices . analyze ( param )
77+ results . then (
78+ ( x ) => {
79+ res . body . resultAnalyzers . push ( { analyzer : analyzer , id : id , tokens : x . body . tokens } ) ;
80+ resolve ( res ) ;
81+ }
82+ ) ;
83+ results . catch ( error => {
8084 reject ( convertEsError ( response , error ) ) ;
8185 } ) ;
8286 } ) ;
8387 } ;
8488
8589 if ( Array . isArray ( request . body . analyzers ) && request . body . analyzers . length >= 1 ) {
8690 try {
87- const response = await Promise . all ( request . body . analyzers . map ( getAnalyzerResult ) ) ;
88- res . resultAnalyzers . sort (
91+ const res_promise = await Promise . all ( request . body . analyzers . map ( getAnalyzerResult ) ) ;
92+ res . body . resultAnalyzers . sort (
8993 function ( a , b ) {
9094 if ( a . id < b . id ) return - 1 ;
9195 if ( a . id > b . id ) return 1 ;
9296 return 0 ;
9397 }
9498 ) ;
95- return res ;
99+ return response . ok ( res ) ;
96100 } catch ( error ) {
97101 return convertEsError ( response , error ) ;
98102 }
99103 } else {
100- return res ;
104+ return response . ok ( res ) ;
101105 }
102106 }
103107 ) ;
0 commit comments