@@ -132,13 +132,13 @@ public static List<AlarmLogMessage> search(ElasticsearchClient client,
132132 case MESSAGE :
133133 boolQuery .must (WildcardQuery .of (w -> w
134134 .field (MESSAGE )
135- .value (parameter .getValue ().strip (). toUpperCase () ))._toQuery ()
135+ .value (parameter .getValue ().strip ()))._toQuery ()
136136 );
137137 break ;
138138 case CURRENTMESSAGE :
139139 boolQuery .must (WildcardQuery .of (w -> w
140140 .field (CURRENTMESSAGE )
141- .value (parameter .getValue ().strip (). toUpperCase () ))._toQuery ()
141+ .value (parameter .getValue ().strip ()))._toQuery ()
142142 );
143143 break ;
144144 case USER :
@@ -157,70 +157,69 @@ public static List<AlarmLogMessage> search(ElasticsearchClient client,
157157 // Unsupported search parameters are ignored
158158 break ;
159159 }
160+ }
160161
161- if (!configSet ) {
162- boolQuery .must (Query .of (q -> q
163- .wildcard (WildcardQuery .of (w -> w
164- .field ("config" )
165- .value ("*" )
166- )
167- )
168- )
169- );
170- }
171-
172- // Add the temporal queries
173- if (temporalSearch ) {
174- // TODO check that the start is before the end
175- //Effectively final
176- String finalFrom = from ;
177- String finalTo = to ;
178- boolQuery .must (
179- Query .of (q -> q
180- .range (RangeQuery .of (r -> r
181- .field ("message_time" )
182- .from (finalFrom )
183- .to (finalTo )
184- )
185- )
186- )
187- );
188- }
189-
190- int finalSize = maxSize ; //Effectively final
191- SearchRequest searchRequest = SearchRequest .of (r -> r
192- .query (Query .of (q -> q
193- .bool (boolQuery .build ())
162+ if (!configSet ) {
163+ boolQuery .must (Query .of (q -> q
164+ .wildcard (WildcardQuery .of (w -> w
165+ .field ("config" )
166+ .value ("*" )
167+ )
194168 )
195169 )
196- .size (finalSize )
197- .sort (SortOptions .of (o -> o
198- .field (FieldSort .of (f -> f
199- .field ("message_time" )
200- .order (SortOrder .Desc )
201- )
170+ );
171+ }
172+
173+ // Add the temporal queries
174+ if (temporalSearch ) {
175+ // TODO check that the start is before the end
176+ //Effectively final
177+ String finalFrom = from ;
178+ String finalTo = to ;
179+ boolQuery .must (
180+ Query .of (q -> q
181+ .range (RangeQuery .of (r -> r
182+ .field ("message_time" )
183+ .from (finalFrom )
184+ .to (finalTo )
202185 )
203186 )
204187 )
205188 );
206- final List <AlarmLogMessage > result = new ArrayList <>();
207- try {
208- SearchResponse <JsonNode > strResponse = client .search (searchRequest , JsonNode .class );
209- return strResponse .hits ().hits ().stream ().map (hit -> {
210- JsonNode jsonNode = hit .source ();
211- try {
212- return mapper .treeToValue (jsonNode , AlarmLogMessage .class );
213- } catch (JsonProcessingException e ) {
214- logger .log (Level .SEVERE , "Failed to parse the searched alarm log messages. " + hit , e );
215- }
216- return null ;
217- }).collect (Collectors .toList ());
218- } catch (IOException e ) {
219- logger .log (Level .SEVERE , "Failed to search for alarm logs " , e );
220- }
221- return result ;
222189 }
223- return null ;
190+
191+ int finalSize = maxSize ; //Effectively final
192+ SearchRequest searchRequest = SearchRequest .of (r -> r
193+ .query (Query .of (q -> q
194+ .bool (boolQuery .build ())
195+ )
196+ )
197+ .size (finalSize )
198+ .sort (SortOptions .of (o -> o
199+ .field (FieldSort .of (f -> f
200+ .field ("message_time" )
201+ .order (SortOrder .Desc )
202+ )
203+ )
204+ )
205+ )
206+ );
207+ final List <AlarmLogMessage > result = new ArrayList <>();
208+ try {
209+ SearchResponse <JsonNode > strResponse = client .search (searchRequest , JsonNode .class );
210+ return strResponse .hits ().hits ().stream ().map (hit -> {
211+ JsonNode jsonNode = hit .source ();
212+ try {
213+ return mapper .treeToValue (jsonNode , AlarmLogMessage .class );
214+ } catch (JsonProcessingException e ) {
215+ logger .log (Level .SEVERE , "Failed to parse the searched alarm log messages. " + hit , e );
216+ }
217+ return null ;
218+ }).collect (Collectors .toList ());
219+ } catch (IOException e ) {
220+ logger .log (Level .SEVERE , "Failed to search for alarm logs " , e );
221+ }
222+ return result ;
224223 }
225224
226225}
0 commit comments