Skip to content

Commit 785e8d6

Browse files
refactoring to use builder and setting exclude value from semantic_text mapper
1 parent 5572275 commit 785e8d6

File tree

4 files changed

+84
-25
lines changed

4 files changed

+84
-25
lines changed

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

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,8 @@ public Builder ignoreAbove(int ignoreAbove) {
301301
return this;
302302
}
303303

304-
public Builder excludeFromFieldCaps(boolean excludeFromFieldCaps) {
305-
this.excludeFromFieldCaps = excludeFromFieldCaps;
304+
public Builder excludeFromFieldCaps(boolean value) {
305+
this.excludeFromFieldCaps = value;
306306
return this;
307307
}
308308

@@ -415,7 +415,8 @@ private KeywordFieldType buildFieldType(MapperBuilderContext context, FieldType
415415
searchAnalyzer,
416416
quoteAnalyzer,
417417
this,
418-
context.isSourceSynthetic()
418+
context.isSourceSynthetic(),
419+
excludeFromFieldCaps
419420
);
420421
}
421422

@@ -456,7 +457,6 @@ public KeywordFieldMapper build(MapperBuilderContext context) {
456457
);
457458

458459
KeywordFieldType keywordFieldType = buildFieldType(context, fieldtype);
459-
keywordFieldType.setExcludeFromFieldCaps(excludeFromFieldCaps);
460460
return new KeywordFieldMapper(
461461
leafName(),
462462
fieldtype,
@@ -525,14 +525,37 @@ public KeywordFieldType(
525525
NamedAnalyzer quoteAnalyzer,
526526
Builder builder,
527527
boolean isSyntheticSource
528+
) {
529+
this(
530+
name,
531+
fieldType,
532+
normalizer,
533+
searchAnalyzer,
534+
quoteAnalyzer,
535+
builder,
536+
isSyntheticSource,
537+
false
538+
);
539+
}
540+
541+
public KeywordFieldType(
542+
String name,
543+
FieldType fieldType,
544+
NamedAnalyzer normalizer,
545+
NamedAnalyzer searchAnalyzer,
546+
NamedAnalyzer quoteAnalyzer,
547+
Builder builder,
548+
boolean isSyntheticSource,
549+
boolean excludeFromFieldCaps
528550
) {
529551
super(
530552
name,
531553
fieldType.indexOptions() != IndexOptions.NONE && builder.indexCreatedVersion.isLegacyIndexVersion() == false,
532554
fieldType.stored(),
533555
builder.hasDocValues.getValue(),
534556
textSearchInfo(fieldType, builder.similarity.getValue(), searchAnalyzer, quoteAnalyzer),
535-
builder.meta.getValue()
557+
builder.meta.getValue(),
558+
excludeFromFieldCaps
536559
);
537560
this.eagerGlobalOrdinals = builder.eagerGlobalOrdinals.getValue();
538561
this.normalizer = normalizer;

server/src/main/java/org/elasticsearch/index/mapper/vectors/DenseVectorFieldMapper.java

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,6 @@ public static class Builder extends FieldMapper.Builder {
188188
final IndexVersion indexVersionCreated;
189189
private boolean excludeFromFieldCaps = false;
190190

191-
public Builder(String name, IndexVersion indexVersionCreated, boolean excludeFromFieldCaps) {
192-
this(name, indexVersionCreated);
193-
this.excludeFromFieldCaps = excludeFromFieldCaps;
194-
}
195-
196191
public Builder(String name, IndexVersion indexVersionCreated) {
197192
super(name);
198193
this.indexVersionCreated = indexVersionCreated;
@@ -306,6 +301,11 @@ public Builder indexOptions(IndexOptions indexOptions) {
306301
return this;
307302
}
308303

304+
public Builder excludeFromFieldCaps(boolean value) {
305+
this.excludeFromFieldCaps = value;
306+
return this;
307+
}
308+
309309
@Override
310310
public DenseVectorFieldMapper build(MapperBuilderContext context) {
311311
DenseVectorFieldType denseVectorFieldType = new DenseVectorFieldType(
@@ -316,9 +316,9 @@ public DenseVectorFieldMapper build(MapperBuilderContext context) {
316316
indexed.getValue(),
317317
similarity.getValue(),
318318
indexOptions.getValue(),
319-
meta.getValue()
319+
meta.getValue(),
320+
excludeFromFieldCaps
320321
);
321-
denseVectorFieldType.setExcludeFromFieldCaps(this.excludeFromFieldCaps);
322322
// Validate again here because the dimensions or element type could have been set programmatically,
323323
// which affects index option validity
324324
validate();
@@ -2096,7 +2096,31 @@ public DenseVectorFieldType(
20962096
IndexOptions indexOptions,
20972097
Map<String, String> meta
20982098
) {
2099-
super(name, indexed, false, indexed == false, TextSearchInfo.NONE, meta);
2099+
this(
2100+
name,
2101+
indexVersionCreated,
2102+
elementType,
2103+
dims,
2104+
indexed,
2105+
similarity,
2106+
indexOptions,
2107+
meta,
2108+
false
2109+
);
2110+
}
2111+
2112+
public DenseVectorFieldType(
2113+
String name,
2114+
IndexVersion indexVersionCreated,
2115+
ElementType elementType,
2116+
Integer dims,
2117+
boolean indexed,
2118+
VectorSimilarity similarity,
2119+
IndexOptions indexOptions,
2120+
Map<String, String> meta,
2121+
boolean excludeFromFieldCaps
2122+
) {
2123+
super(name, indexed, false, indexed == false, TextSearchInfo.NONE, meta, excludeFromFieldCaps);
21002124
this.elementType = elementType;
21012125
this.dims = dims;
21022126
this.indexed = indexed;

server/src/main/java/org/elasticsearch/index/mapper/vectors/SparseVectorFieldMapper.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,16 @@ public Builder(String name) {
7979
super(name);
8080
}
8181

82-
public Builder(String name, boolean excludeFromFieldCaps) {
83-
super(name);
84-
this.excludeFromFieldCaps = excludeFromFieldCaps;
85-
}
86-
8782
public Builder setStored(boolean value) {
8883
stored.setValue(value);
8984
return this;
9085
}
9186

87+
public Builder setExcludeFromFieldCaps(boolean value) {
88+
excludeFromFieldCaps = value;
89+
return this;
90+
}
91+
9292
@Override
9393
protected Parameter<?>[] getParameters() {
9494
return new Parameter<?>[] { stored, meta };
@@ -99,9 +99,9 @@ public SparseVectorFieldMapper build(MapperBuilderContext context) {
9999
SparseVectorFieldType sparseVectorFieldType = new SparseVectorFieldType(
100100
context.buildFullName(leafName()),
101101
stored.getValue(),
102-
meta.getValue()
102+
meta.getValue(),
103+
excludeFromFieldCaps
103104
);
104-
sparseVectorFieldType.setExcludeFromFieldCaps(excludeFromFieldCaps);
105105
return new SparseVectorFieldMapper(leafName(), sparseVectorFieldType, builderParams(this, context));
106106
}
107107
}
@@ -119,7 +119,11 @@ public SparseVectorFieldMapper build(MapperBuilderContext context) {
119119
public static final class SparseVectorFieldType extends MappedFieldType {
120120

121121
public SparseVectorFieldType(String name, boolean isStored, Map<String, String> meta) {
122-
super(name, true, isStored, false, TextSearchInfo.SIMPLE_MATCH_ONLY, meta);
122+
this(name, isStored, meta, false);
123+
}
124+
125+
public SparseVectorFieldType(String name, boolean isStored, Map<String, String> meta, boolean excludeFromFieldCaps) {
126+
super(name, true, isStored, false, TextSearchInfo.SIMPLE_MATCH_ONLY, meta, excludeFromFieldCaps);
123127
}
124128

125129
@Override

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/mapper/OffsetSourceFieldMapper.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,21 +107,25 @@ public static class Builder extends FieldMapper.Builder {
107107
CharsetFormat.class
108108
);
109109
private final Parameter<Map<String, String>> meta = Parameter.metaParam();
110+
private boolean excludeFromFieldCaps = false;
110111

111112
public Builder(String name) {
112113
super(name);
113114
}
114115

116+
public Builder excludeFromFieldCaps(boolean value) {
117+
excludeFromFieldCaps = value;
118+
return this;
119+
}
120+
115121
@Override
116122
protected Parameter<?>[] getParameters() {
117123
return new Parameter<?>[] { meta, charset };
118124
}
119125

120126
@Override
121127
public OffsetSourceFieldMapper build(MapperBuilderContext context) {
122-
OffsetSourceFieldType fieldType = new OffsetSourceFieldType(context.buildFullName(leafName()), charset.get(), meta.getValue());
123-
// explicitly setting the field type to be not available for field caps
124-
fieldType.setExcludeFromFieldCaps(true);
128+
OffsetSourceFieldType fieldType = new OffsetSourceFieldType(context.buildFullName(leafName()), charset.get(), meta.getValue(), this.excludeFromFieldCaps);
125129

126130
return new OffsetSourceFieldMapper(leafName(), fieldType, builderParams(this, context));
127131
}
@@ -133,7 +137,11 @@ public static final class OffsetSourceFieldType extends MappedFieldType {
133137
private final CharsetFormat charset;
134138

135139
public OffsetSourceFieldType(String name, CharsetFormat charset, Map<String, String> meta) {
136-
super(name, true, false, false, TextSearchInfo.NONE, meta);
140+
this(name, charset, meta, false);
141+
}
142+
143+
public OffsetSourceFieldType(String name, CharsetFormat charset, Map<String, String> meta, boolean excludeFromFieldCaps) {
144+
super(name, true, false, false, TextSearchInfo.NONE, meta, excludeFromFieldCaps);
137145
this.charset = charset;
138146
}
139147

0 commit comments

Comments
 (0)