59
59
import java .util .function .Supplier ;
60
60
import java .util .regex .Pattern ;
61
61
62
- import static java .util .Arrays .asList ;
63
62
import static java .util .Collections .emptyList ;
64
63
import static java .util .Collections .emptyMap ;
65
- import static java .util .Collections .emptySet ;
66
64
import static org .elasticsearch .action .ActionListener .wrap ;
67
65
import static org .elasticsearch .common .Strings .hasText ;
68
66
import static org .elasticsearch .common .regex .Regex .simpleMatch ;
67
+ import static org .elasticsearch .common .util .CollectionUtils .arrayAsArrayList ;
69
68
import static org .elasticsearch .transport .RemoteClusterAware .buildRemoteIndexName ;
70
69
import static org .elasticsearch .xpack .ql .type .DataTypes .DATETIME ;
71
70
import static org .elasticsearch .xpack .ql .type .DataTypes .KEYWORD ;
@@ -659,15 +658,12 @@ private static List<EsIndex> buildIndices(
659
658
}
660
659
}
661
660
662
- List <String > resolvedIndices = new ArrayList <>(asList (fieldCapsResponse .getIndices ()));
663
- int mapSize = CollectionUtils .mapSize (resolvedIndices .size () + resolvedAliases .size ());
664
- Map <String , Fields > indices = Maps .newLinkedHashMapWithExpectedSize (mapSize );
661
+ final List <String > resolvedIndices = arrayAsArrayList (fieldCapsResponse .getIndices ());
662
+ Map <String , Fields > indices = Maps .newLinkedHashMapWithExpectedSize (resolvedIndices .size () + resolvedAliases .size ());
665
663
Pattern pattern = javaRegex != null ? Pattern .compile (javaRegex ) : null ;
666
664
667
665
// sort fields in reverse order to build the field hierarchy
668
- Set <Entry <String , Map <String , FieldCapabilities >>> sortedFields = new TreeSet <>(
669
- Collections .reverseOrder (Comparator .comparing (Entry ::getKey ))
670
- );
666
+ Set <Entry <String , Map <String , FieldCapabilities >>> sortedFields = new TreeSet <>(Collections .reverseOrder (Entry .comparingByKey ()));
671
667
final Map <String , Map <String , FieldCapabilities >> fieldCaps = fieldCapsResponse .get ();
672
668
sortedFields .addAll (fieldCaps .entrySet ());
673
669
@@ -682,29 +678,18 @@ private static List<EsIndex> buildIndices(
682
678
// apply verification for fields belonging to index aliases
683
679
Map <String , InvalidMappedField > invalidFieldsForAliases = getInvalidFieldsForAliases (fieldName , types , aliases );
684
680
685
- // filter unmapped
686
- FieldCapabilities unmapped = types .get (UNMAPPED );
687
- Set <String > unmappedIndices = unmapped != null ? new HashSet <>(asList (unmapped .indices ())) : emptySet ();
688
-
689
681
// check each type
690
682
for (Entry <String , FieldCapabilities > typeEntry : types .entrySet ()) {
683
+ if (UNMAPPED .equals (typeEntry .getKey ())) {
684
+ continue ;
685
+ }
691
686
FieldCapabilities typeCap = typeEntry .getValue ();
692
687
String [] capIndices = typeCap .indices ();
693
688
694
689
// compute the actual indices - if any are specified, take into account the unmapped indices
695
- List <String > concreteIndices = null ;
690
+ final List <String > concreteIndices ;
696
691
if (capIndices != null ) {
697
- if (unmappedIndices .isEmpty ()) {
698
- concreteIndices = new ArrayList <>(asList (capIndices ));
699
- } else {
700
- concreteIndices = new ArrayList <>(capIndices .length );
701
- for (String capIndex : capIndices ) {
702
- // add only indices that have a mapping
703
- if (unmappedIndices .contains (capIndex ) == false ) {
704
- concreteIndices .add (capIndex );
705
- }
706
- }
707
- }
692
+ concreteIndices = arrayAsArrayList (capIndices );
708
693
} else {
709
694
concreteIndices = resolvedIndices ;
710
695
}
@@ -727,11 +712,7 @@ private static List<EsIndex> buildIndices(
727
712
// TODO is split still needed?
728
713
if (pattern == null || pattern .matcher (splitQualifiedIndex (index ).v2 ()).matches () || isIndexAlias ) {
729
714
String indexName = isIndexAlias ? index : indexNameProcessor .apply (index );
730
- Fields indexFields = indices .get (indexName );
731
- if (indexFields == null ) {
732
- indexFields = new Fields ();
733
- indices .put (indexName , indexFields );
734
- }
715
+ Fields indexFields = indices .computeIfAbsent (indexName , k -> new Fields ());
735
716
EsField field = indexFields .flattedMapping .get (fieldName );
736
717
boolean createField = false ;
737
718
if (isIndexAlias == false ) {
0 commit comments