Skip to content

Replace tuple with record #128976

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jun 11, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.core.Nullable;
import org.elasticsearch.core.Tuple;
import org.elasticsearch.index.mapper.IdFieldMapper;
import org.elasticsearch.index.mapper.IgnoredFieldMapper;
import org.elasticsearch.index.mapper.IndexModeFieldMapper;
Expand All @@ -26,8 +25,6 @@
import java.util.Map;
import java.util.Objects;

import static org.elasticsearch.core.Tuple.tuple;

public class MetadataAttribute extends TypedAttribute {
public static final String TIMESTAMP_FIELD = "@timestamp"; // this is not a true metadata attribute
public static final String TSID_FIELD = "_tsid";
Expand All @@ -40,23 +37,19 @@ public class MetadataAttribute extends TypedAttribute {
MetadataAttribute::readFrom
);

private static final Map<String, Tuple<DataType, Boolean>> ATTRIBUTES_MAP = Map.of(
"_version",
tuple(DataType.LONG, false), // _version field is not searchable
INDEX,
tuple(DataType.KEYWORD, true),
IdFieldMapper.NAME,
tuple(DataType.KEYWORD, false), // actually searchable, but fielddata access on the _id field is disallowed by default
IgnoredFieldMapper.NAME,
tuple(DataType.KEYWORD, true),
SourceFieldMapper.NAME,
tuple(DataType.SOURCE, false),
IndexModeFieldMapper.NAME,
tuple(DataType.KEYWORD, true),
SCORE,
tuple(DataType.DOUBLE, false)
private static final Map<String, MetadataAttributeConfiguration> ATTRIBUTES_MAP = Map.ofEntries(
Map.entry("_version", new MetadataAttributeConfiguration(DataType.LONG, false)),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: lost a comment here. Not sure how much we care.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The last attribute of MetadataAttributeConfiguration is searchable=false.
I do not think it is worth keeping it as it does not bring the reason why the field is not searchable other than repeating the configuration.

Map.entry(INDEX, new MetadataAttributeConfiguration(DataType.KEYWORD, true)),
// actually _id is searchable, but fielddata access on it is disallowed by default
Map.entry(IdFieldMapper.NAME, new MetadataAttributeConfiguration(DataType.KEYWORD, false)),
Map.entry(IgnoredFieldMapper.NAME, new MetadataAttributeConfiguration(DataType.KEYWORD, true)),
Map.entry(SourceFieldMapper.NAME, new MetadataAttributeConfiguration(DataType.SOURCE, false)),
Map.entry(IndexModeFieldMapper.NAME, new MetadataAttributeConfiguration(DataType.KEYWORD, true)),
Map.entry(SCORE, new MetadataAttributeConfiguration(DataType.DOUBLE, false))
);

private record MetadataAttributeConfiguration(DataType dataType, boolean searchable) {}

private final boolean searchable;

public MetadataAttribute(
Expand Down Expand Up @@ -160,12 +153,12 @@ public boolean searchable() {

public static MetadataAttribute create(Source source, String name) {
var t = ATTRIBUTES_MAP.get(name);
return t != null ? new MetadataAttribute(source, name, t.v1(), t.v2()) : null;
return t != null ? new MetadataAttribute(source, name, t.dataType(), t.searchable()) : null;
}

public static DataType dataType(String name) {
var t = ATTRIBUTES_MAP.get(name);
return t != null ? t.v1() : null;
return t != null ? t.dataType() : null;
}

public static boolean isSupported(String name) {
Expand Down