11
11
import org .elasticsearch .common .io .stream .StreamInput ;
12
12
import org .elasticsearch .common .io .stream .StreamOutput ;
13
13
import org .elasticsearch .core .Nullable ;
14
- import org .elasticsearch .core .Tuple ;
15
14
import org .elasticsearch .index .mapper .IdFieldMapper ;
16
15
import org .elasticsearch .index .mapper .IgnoredFieldMapper ;
17
16
import org .elasticsearch .index .mapper .IndexModeFieldMapper ;
26
25
import java .util .Map ;
27
26
import java .util .Objects ;
28
27
29
- import static org .elasticsearch .core .Tuple .tuple ;
30
-
31
28
public class MetadataAttribute extends TypedAttribute {
32
29
public static final String TIMESTAMP_FIELD = "@timestamp" ; // this is not a true metadata attribute
33
30
public static final String TSID_FIELD = "_tsid" ;
@@ -40,23 +37,19 @@ public class MetadataAttribute extends TypedAttribute {
40
37
MetadataAttribute ::readFrom
41
38
);
42
39
43
- private static final Map <String , Tuple <DataType , Boolean >> ATTRIBUTES_MAP = Map .of (
44
- "_version" ,
45
- tuple (DataType .LONG , false ), // _version field is not searchable
46
- INDEX ,
47
- tuple (DataType .KEYWORD , true ),
48
- IdFieldMapper .NAME ,
49
- tuple (DataType .KEYWORD , false ), // actually searchable, but fielddata access on the _id field is disallowed by default
50
- IgnoredFieldMapper .NAME ,
51
- tuple (DataType .KEYWORD , true ),
52
- SourceFieldMapper .NAME ,
53
- tuple (DataType .SOURCE , false ),
54
- IndexModeFieldMapper .NAME ,
55
- tuple (DataType .KEYWORD , true ),
56
- SCORE ,
57
- tuple (DataType .DOUBLE , false )
40
+ private static final Map <String , MetadataAttributeConfiguration > ATTRIBUTES_MAP = Map .ofEntries (
41
+ Map .entry ("_version" , new MetadataAttributeConfiguration (DataType .LONG , false )),
42
+ Map .entry (INDEX , new MetadataAttributeConfiguration (DataType .KEYWORD , true )),
43
+ // actually _id is searchable, but fielddata access on it is disallowed by default
44
+ Map .entry (IdFieldMapper .NAME , new MetadataAttributeConfiguration (DataType .KEYWORD , false )),
45
+ Map .entry (IgnoredFieldMapper .NAME , new MetadataAttributeConfiguration (DataType .KEYWORD , true )),
46
+ Map .entry (SourceFieldMapper .NAME , new MetadataAttributeConfiguration (DataType .SOURCE , false )),
47
+ Map .entry (IndexModeFieldMapper .NAME , new MetadataAttributeConfiguration (DataType .KEYWORD , true )),
48
+ Map .entry (SCORE , new MetadataAttributeConfiguration (DataType .DOUBLE , false ))
58
49
);
59
50
51
+ private record MetadataAttributeConfiguration (DataType dataType , boolean searchable ) {}
52
+
60
53
private final boolean searchable ;
61
54
62
55
public MetadataAttribute (
@@ -160,12 +153,12 @@ public boolean searchable() {
160
153
161
154
public static MetadataAttribute create (Source source , String name ) {
162
155
var t = ATTRIBUTES_MAP .get (name );
163
- return t != null ? new MetadataAttribute (source , name , t .v1 (), t .v2 ()) : null ;
156
+ return t != null ? new MetadataAttribute (source , name , t .dataType (), t .searchable ()) : null ;
164
157
}
165
158
166
159
public static DataType dataType (String name ) {
167
160
var t = ATTRIBUTES_MAP .get (name );
168
- return t != null ? t .v1 () : null ;
161
+ return t != null ? t .dataType () : null ;
169
162
}
170
163
171
164
public static boolean isSupported (String name ) {
0 commit comments