Skip to content

Commit 5572275

Browse files
Adding support for generic field types
1 parent 06caf66 commit 5572275

File tree

4 files changed

+61
-9
lines changed

4 files changed

+61
-9
lines changed

server/src/main/java/org/elasticsearch/index/mapper/MappedFieldType.java

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public abstract class MappedFieldType {
6868
private final boolean isStored;
6969
private final TextSearchInfo textSearchInfo;
7070
private final Map<String, String> meta;
71-
private boolean excludeFromFieldCaps;
71+
private final boolean excludeFromFieldCaps;
7272

7373
public MappedFieldType(
7474
String name,
@@ -77,6 +77,18 @@ public MappedFieldType(
7777
boolean hasDocValues,
7878
TextSearchInfo textSearchInfo,
7979
Map<String, String> meta
80+
) {
81+
this(name, isIndexed, isStored, hasDocValues, textSearchInfo, meta, false);
82+
}
83+
84+
public MappedFieldType(
85+
String name,
86+
boolean isIndexed,
87+
boolean isStored,
88+
boolean hasDocValues,
89+
TextSearchInfo textSearchInfo,
90+
Map<String, String> meta,
91+
boolean excludeFromFieldCaps
8092
) {
8193
this.name = Mapper.internFieldName(name);
8294
this.isIndexed = isIndexed;
@@ -86,6 +98,7 @@ public MappedFieldType(
8698
// meta should be sorted but for the one item or empty case we can fall back to immutable maps to save some memory since order is
8799
// irrelevant
88100
this.meta = meta.size() <= 1 ? Map.copyOf(meta) : meta;
101+
this.excludeFromFieldCaps = excludeFromFieldCaps;
89102
}
90103

91104
/**
@@ -123,11 +136,7 @@ public IndexFieldData.Builder fielddataBuilder(FieldDataContext fieldDataContext
123136

124137
/** Returns the field family type, as used in field capabilities */
125138
public String familyTypeName() {
126-
return excludeFromFieldCaps ? null : typeName();
127-
}
128-
129-
public void setExcludeFromFieldCaps(boolean exclude) {
130-
this.excludeFromFieldCaps = exclude;
139+
return typeName();
131140
}
132141

133142
public String name() {
@@ -175,6 +184,13 @@ public final boolean isStored() {
175184
return isStored;
176185
}
177186

187+
/**
188+
* @return true if fieldType is subfields of semantic_text type
189+
*/
190+
public boolean excludeFromFieldCaps() {
191+
return excludeFromFieldCaps;
192+
}
193+
178194
/**
179195
* If the field supports using the indexed data to speed up operations related to ordering of data, such as sorting or aggs, return
180196
* a function for doing that. If it is unsupported for this field type, there is no need to override this method.

server/src/main/java/org/elasticsearch/index/mapper/SimpleMappedFieldType.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,19 @@ protected SimpleMappedFieldType(
3030
TextSearchInfo textSearchInfo,
3131
Map<String, String> meta
3232
) {
33-
super(name, isIndexed, isStored, hasDocValues, textSearchInfo, meta);
33+
this(name, isIndexed, isStored, hasDocValues, textSearchInfo, meta, false);
34+
}
35+
36+
protected SimpleMappedFieldType(
37+
String name,
38+
boolean isIndexed,
39+
boolean isStored,
40+
boolean hasDocValues,
41+
TextSearchInfo textSearchInfo,
42+
Map<String, String> meta,
43+
boolean excludeFromFieldCaps
44+
) {
45+
super(name, isIndexed, isStored, hasDocValues, textSearchInfo, meta, excludeFromFieldCaps);
3446
}
3547

3648
@Override

server/src/main/java/org/elasticsearch/index/mapper/StringFieldType.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,19 @@ public StringFieldType(
5151
TextSearchInfo textSearchInfo,
5252
Map<String, String> meta
5353
) {
54-
super(name, isIndexed, isStored, hasDocValues, textSearchInfo, meta);
54+
this(name, isIndexed, isStored, hasDocValues, textSearchInfo, meta, false);
55+
}
56+
57+
public StringFieldType(
58+
String name,
59+
boolean isIndexed,
60+
boolean isStored,
61+
boolean hasDocValues,
62+
TextSearchInfo textSearchInfo,
63+
Map<String, String> meta,
64+
boolean excludeFromFieldCaps
65+
) {
66+
super(name, isIndexed, isStored, hasDocValues, textSearchInfo, meta, excludeFromFieldCaps);
5567
}
5668

5769
@Override

server/src/main/java/org/elasticsearch/index/mapper/TermBasedFieldType.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,19 @@ public TermBasedFieldType(
3434
TextSearchInfo textSearchInfo,
3535
Map<String, String> meta
3636
) {
37-
super(name, isIndexed, isStored, hasDocValues, textSearchInfo, meta);
37+
this(name, isIndexed, isStored, hasDocValues, textSearchInfo, meta, false);
38+
}
39+
40+
public TermBasedFieldType(
41+
String name,
42+
boolean isIndexed,
43+
boolean isStored,
44+
boolean hasDocValues,
45+
TextSearchInfo textSearchInfo,
46+
Map<String, String> meta,
47+
boolean excludeFromFieldCaps
48+
) {
49+
super(name, isIndexed, isStored, hasDocValues, textSearchInfo, meta, excludeFromFieldCaps);
3850
}
3951

4052
/** Returns the indexed value used to construct search "values".

0 commit comments

Comments
 (0)