@@ -23,8 +23,10 @@ import org.joor.Reflect.*
2323import org .joor .ReflectException
2424import tech .beshu .ror .accesscontrol .domain .FieldLevelSecurity
2525import tech .beshu .ror .accesscontrol .domain .FieldLevelSecurity .FieldsRestrictions
26+ import tech .beshu .ror .es .EsVersion
2627import tech .beshu .ror .es .handler .response .FieldsFiltering
2728import tech .beshu .ror .es .handler .response .FieldsFiltering .NonMetadataDocumentFields
29+ import tech .beshu .ror .es .utils .EsqlRequestHelper .{ClassificationError , EsqlRequestClassification , IndexTable }
2830import tech .beshu .ror .syntax .*
2931import tech .beshu .ror .utils .ScalaOps .*
3032
@@ -33,7 +35,7 @@ import java.util.List as JList
3335import scala .jdk .CollectionConverters .*
3436import scala .util .{Failure , Success , Try }
3537
36- object EsqlRequestHelper {
38+ class EsqlRequestHelper ( esVersion : EsVersion ) {
3739
3840 def modifyIndicesOf (request : CompositeIndicesRequest ,
3941 requestTables : NonEmptyList [IndexTable ],
@@ -117,15 +119,36 @@ object EsqlRequestHelper {
117119 }
118120
119121 private def indicesFrom (statement : Any ) = {
120- val preAnalyze = doPreAnalyze(newPreAnalyzer, statement)
121- val indexPattern = indexPatternFrom(preAnalyze)
122+ val plan = esVersion match {
123+ case v if v >= EsVersion (9 , 3 , 0 ) => on(statement).call(" plan" ).get[Any ]()
124+ case _ => statement
125+ }
126+ val preAnalysis = doPreAnalyze(newPreAnalyzer, plan)
127+ esVersion match {
128+ case v if v >= EsVersion (9 , 3 , 0 ) => indicesFromPreAnalysisForEsEqualOrAbove930(preAnalysis)
129+ case _ => indicesFromPreAnalysisForEsBelow930(preAnalysis)
130+ }
131+ }
132+
133+ private def indicesFromPreAnalysisForEsBelow930 (preAnalysis : Any ) = {
134+ val indexPattern = indexPatternFrom(preAnalysis)
122135 val indexPatternString = indexPatternStringFrom(indexPattern)
123136 NonEmptyList
124137 .fromList(splitIntoIndices(indexPatternString))
125138 .map(IndexTable (indexPatternString, _))
126139 .toList
127140 }
128141
142+ private def indicesFromPreAnalysisForEsEqualOrAbove930 (preAnalysis : Any ) = {
143+ val indexesMap = on(preAnalysis).get[java.util.Map [Any , Any ]](" indexes" )
144+ indexesMap.keySet().asScala.toList.flatMap { indexPattern =>
145+ val indexPatternString = on(indexPattern).call(" indexPattern" ).get[String ]()
146+ NonEmptyList
147+ .fromList(splitIntoIndices(indexPatternString))
148+ .map(IndexTable (indexPatternString, _))
149+ }
150+ }
151+
129152 private def splitIntoIndices (tableString : String ) = {
130153 tableString.split(',' ).asSafeList.filter(_.nonEmpty)
131154 }
@@ -243,6 +266,9 @@ object EsqlRequestHelper {
243266 }
244267 }
245268 }
269+ }
270+
271+ object EsqlRequestHelper {
246272
247273 final case class IndexTable (tableStringInQuery : String , indices : NonEmptyList [String ])
248274
@@ -258,4 +284,4 @@ object EsqlRequestHelper {
258284 object ClassificationError {
259285 final case class ParsingException (cause : Throwable ) extends ClassificationError
260286 }
261- }
287+ }
0 commit comments