Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into dot-prefix-validation
Browse files Browse the repository at this point in the history
  • Loading branch information
dakrone committed Sep 10, 2024
2 parents a22fa92 + 5c9710c commit 99e83c3
Show file tree
Hide file tree
Showing 84 changed files with 1,090 additions and 1,125 deletions.
1 change: 0 additions & 1 deletion .ci/scripts/resolve-dra-manifest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ if [ "$LATEST_VERSION" != "$ES_VERSION" ]; then
fi

echo "Using branch $NEW_BRANCH instead of $BRANCH." 1>&2
echo "https://artifacts-$WORKFLOW.elastic.co/$ARTIFACT/latest/$NEW_BRANCH.json"
LATEST_BUILD=$(fetch_build $WORKFLOW $ARTIFACT $NEW_BRANCH)
fi

Expand Down
5 changes: 4 additions & 1 deletion distribution/docker/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -515,14 +515,17 @@ subprojects { Project subProject ->
base = DockerBase.CLOUD_ESS
} else if (subProject.name.contains('cloud-')) {
base = DockerBase.CLOUD
} else if (subProject.name.contains('wolfi-')) {
base = DockerBase.WOLFI
}

final String arch = architecture == Architecture.AARCH64 ? '-aarch64' : ''
final String extension = base == DockerBase.UBI ? 'ubi.tar' :
(base == DockerBase.IRON_BANK ? 'ironbank.tar' :
(base == DockerBase.CLOUD ? 'cloud.tar' :
(base == DockerBase.CLOUD_ESS ? 'cloud-ess.tar' :
'docker.tar')))
(base == DockerBase.WOLFI ? 'wolfi.tar' :
'docker.tar'))))
final String artifactName = "elasticsearch${arch}${base.suffix}_test"

final String exportTaskName = taskName("export", architecture, base, 'DockerImage')
Expand Down
8 changes: 8 additions & 0 deletions docs/changelog/112294.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
pr: 112294
summary: "Use fallback synthetic source for `copy_to` and doc_values: false cases"
area: Mapping
type: enhancement
issues:
- 110753
- 110038
- 109546
5 changes: 5 additions & 0 deletions docs/changelog/112713.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 112713
summary: Fix encoding of dynamic arrays in ignored source
area: Logs
type: bug
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -283,35 +283,6 @@ public void testOverrideIgnoreDynamicBeyondLimit() throws IOException {
assertThat(ignoreDynamicBeyondLimitIndexSetting, equalTo("false"));
}

public void testAddNonCompatibleMapping() throws IOException {
var nonCompatibleMappingAdditionTemplate = """
{
"template": {
"mappings": {
"properties": {
"bomb": {
"type": "ip",
"doc_values": false
}
}
}
}
}""";

Exception e = assertThrows(
ResponseException.class,
() -> putComponentTemplate(client, "logs@custom", nonCompatibleMappingAdditionTemplate)
);
assertThat(
e.getMessage(),
containsString("updating component template [logs@custom] results in invalid composable template [logs]")
);
assertThat(
e.getMessage(),
containsString("field [bomb] of type [ip] doesn't support synthetic source because it doesn't have doc values")
);
}

private static Map<String, Object> getMapping(final RestClient client, final String indexName) throws IOException {
final Request request = new Request("GET", "/" + indexName + "/_mapping");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.elasticsearch.logsdb.datageneration.DataGenerator;
import org.elasticsearch.logsdb.datageneration.DataGeneratorSpecification;
import org.elasticsearch.logsdb.datageneration.FieldDataGenerator;
import org.elasticsearch.logsdb.datageneration.FieldType;
import org.elasticsearch.logsdb.datageneration.datasource.DataSourceHandler;
import org.elasticsearch.logsdb.datageneration.datasource.DataSourceRequest;
import org.elasticsearch.logsdb.datageneration.datasource.DataSourceResponse;
Expand Down Expand Up @@ -78,7 +77,18 @@ public DataSourceResponse.ObjectMappingParametersGenerator handle(DataSourceRequ
}))
.withPredefinedFields(
List.of(
new PredefinedField.WithType("host.name", FieldType.KEYWORD),
// Customized because it always needs doc_values for aggregations.
new PredefinedField.WithGenerator("host.name", new FieldDataGenerator() {
@Override
public CheckedConsumer<XContentBuilder, IOException> mappingWriter() {
return b -> b.startObject().field("type", "keyword").endObject();
}

@Override
public CheckedConsumer<XContentBuilder, IOException> fieldValueGenerator() {
return b -> b.value(randomAlphaOfLength(5));
}
}),
// Needed for terms query
new PredefinedField.WithGenerator("method", new FieldDataGenerator() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import org.elasticsearch.index.mapper.DocumentParserContext;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.mapper.MapperBuilderContext;
import org.elasticsearch.index.mapper.SourceLoader;
import org.elasticsearch.index.mapper.SourceValueFetcher;
import org.elasticsearch.index.mapper.StringFieldType;
import org.elasticsearch.index.mapper.StringStoredFieldFieldLoader;
Expand Down Expand Up @@ -433,22 +432,14 @@ public MatchOnlyTextFieldType fieldType() {
}

@Override
protected SyntheticSourceMode syntheticSourceMode() {
return SyntheticSourceMode.NATIVE;
}

@Override
public SourceLoader.SyntheticFieldLoader syntheticFieldLoader() {
if (copyTo().copyToFields().isEmpty() != true) {
throw new IllegalArgumentException(
"field [" + fullPath() + "] of type [" + typeName() + "] doesn't support synthetic source because it declares copy_to"
);
}
return new StringStoredFieldFieldLoader(fieldType().storedFieldNameForSyntheticSource(), leafName()) {
protected SyntheticSourceSupport syntheticSourceSupport() {
var loader = new StringStoredFieldFieldLoader(fieldType().storedFieldNameForSyntheticSource(), leafName()) {
@Override
protected void write(XContentBuilder b, Object value) throws IOException {
b.value((String) value);
}
};

return new SyntheticSourceSupport.Native(loader);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.apache.lucene.search.Query;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.MetadataFieldMapper;
import org.elasticsearch.index.mapper.SourceLoader;
import org.elasticsearch.index.mapper.TextSearchInfo;
import org.elasticsearch.index.mapper.ValueFetcher;
import org.elasticsearch.index.query.SearchExecutionContext;
Expand Down Expand Up @@ -75,9 +74,4 @@ private RankFeatureMetaFieldMapper() {
protected String contentType() {
return CONTENT_TYPE;
}

@Override
public SourceLoader.SyntheticFieldLoader syntheticFieldLoader() {
return SourceLoader.SyntheticFieldLoader.NOTHING;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.elasticsearch.index.mapper.NumberFieldMapper;
import org.elasticsearch.index.mapper.SimpleMappedFieldType;
import org.elasticsearch.index.mapper.SortedNumericDocValuesSyntheticFieldLoader;
import org.elasticsearch.index.mapper.SourceLoader;
import org.elasticsearch.index.mapper.SourceValueFetcher;
import org.elasticsearch.index.mapper.TextSearchInfo;
import org.elasticsearch.index.mapper.TimeSeriesParams;
Expand Down Expand Up @@ -705,32 +704,19 @@ public int docValueCount() {
}

@Override
protected SyntheticSourceMode syntheticSourceMode() {
return SyntheticSourceMode.NATIVE;
}
protected SyntheticSourceSupport syntheticSourceSupport() {
if (hasDocValues) {
var loader = new SortedNumericDocValuesSyntheticFieldLoader(fullPath(), leafName(), ignoreMalformed.value()) {
@Override
protected void writeValue(XContentBuilder b, long value) throws IOException {
b.value(decodeForSyntheticSource(value, scalingFactor));
}
};

@Override
public SourceLoader.SyntheticFieldLoader syntheticFieldLoader() {
if (hasDocValues == false) {
throw new IllegalArgumentException(
"field ["
+ fullPath()
+ "] of type ["
+ typeName()
+ "] doesn't support synthetic source because it doesn't have doc values"
);
}
if (copyTo().copyToFields().isEmpty() != true) {
throw new IllegalArgumentException(
"field [" + fullPath() + "] of type [" + typeName() + "] doesn't support synthetic source because it declares copy_to"
);
return new SyntheticSourceSupport.Native(loader);
}
return new SortedNumericDocValuesSyntheticFieldLoader(fullPath(), leafName(), ignoreMalformed.value()) {
@Override
protected void writeValue(XContentBuilder b, long value) throws IOException {
b.value(decodeForSyntheticSource(value, scalingFactor));
}
};

return super.syntheticSourceSupport();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,12 +470,7 @@ private void mapping(XContentBuilder b) throws IOException {

@Override
public List<SyntheticSourceInvalidExample> invalidExample() throws IOException {
return List.of(
new SyntheticSourceInvalidExample(
equalTo("field [field] of type [scaled_float] doesn't support synthetic source because it doesn't have doc values"),
b -> b.field("type", "scaled_float").field("scaling_factor", 10).field("doc_values", false)
)
);
return List.of();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,3 +351,45 @@ tsdb:
"@timestamp" : "2000-01-01T00:00:00.000Z"
"dimension" : "a"
foo: "Apache Lucene powers Elasticsearch"

---
synthetic_source with copy_to:
- requires:
cluster_features: ["mapper.source.synthetic_source_with_copy_to_and_doc_values_false"]
reason: requires copy_to support in synthetic source

- do:
indices.create:
index: synthetic_source_test
body:
mappings:
_source:
mode: synthetic
properties:
foo:
type: match_only_text
copy_to: copy
copy:
type: keyword

- do:
index:
index: synthetic_source_test
id: "1"
refresh: true
body:
foo: "Apache Lucene powers Elasticsearch"

- do:
search:
index: synthetic_source_test
body:
fields: ["copy"]

- match: { "hits.total.value": 1 }
- match:
hits.hits.0._source.foo: "Apache Lucene powers Elasticsearch"
- match:
hits.hits.0.fields.copy.0: "Apache Lucene powers Elasticsearch"


6 changes: 0 additions & 6 deletions muted-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,6 @@ tests:
- class: org.elasticsearch.xpack.esql.EsqlAsyncSecurityIT
method: testIndexPatternErrorMessageComparison_ESQL_SearchDSL
issue: https://github.com/elastic/elasticsearch/issues/112630
- class: org.elasticsearch.compute.aggregation.blockhash.BlockHashTests
method: testBytesRefLongHashHugeCombinatorialExplosion {forcePackedHash=false}
issue: https://github.com/elastic/elasticsearch/issues/112442
- class: org.elasticsearch.compute.aggregation.blockhash.BlockHashTests
method: testBytesRefLongHashHugeCombinatorialExplosion {forcePackedHash=true}
issue: https://github.com/elastic/elasticsearch/issues/112443
- class: org.elasticsearch.xpack.ml.integration.MlJobIT
method: testPutJob_GivenFarequoteConfig
issue: https://github.com/elastic/elasticsearch/issues/112382
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.mapper.KeywordFieldMapper;
import org.elasticsearch.index.mapper.MapperBuilderContext;
import org.elasticsearch.index.mapper.SourceLoader;
import org.elasticsearch.index.mapper.StringStoredFieldFieldLoader;
import org.elasticsearch.index.mapper.TextFieldMapper;
import org.elasticsearch.index.mapper.TextParams;
Expand All @@ -46,7 +45,6 @@
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -570,39 +568,23 @@ public FieldMapper.Builder getMergeBuilder() {
}

@Override
protected SyntheticSourceMode syntheticSourceMode() {
return SyntheticSourceMode.NATIVE;
}

@Override
public SourceLoader.SyntheticFieldLoader syntheticFieldLoader() {
if (copyTo().copyToFields().isEmpty() != true) {
throw new IllegalArgumentException(
"field [" + fullPath() + "] of type [" + typeName() + "] doesn't support synthetic source because it declares copy_to"
);
}
protected SyntheticSourceSupport syntheticSourceSupport() {
if (fieldType.stored()) {
return new StringStoredFieldFieldLoader(fullPath(), leafName()) {
var loader = new StringStoredFieldFieldLoader(fullPath(), leafName()) {
@Override
protected void write(XContentBuilder b, Object value) throws IOException {
b.value((String) value);
}
};

return new SyntheticSourceSupport.Native(loader);
}

var kwd = TextFieldMapper.SyntheticSourceHelper.getKeywordFieldMapperForSyntheticSource(this);
if (kwd != null) {
return kwd.syntheticFieldLoader(leafName());
return new SyntheticSourceSupport.Native(kwd.syntheticFieldLoader(leafName()));
}

throw new IllegalArgumentException(
String.format(
Locale.ROOT,
"field [%s] of type [%s] doesn't support synthetic source unless it is stored or has a sub-field of"
+ " type [keyword] with doc values or stored and without a normalizer",
fullPath(),
typeName()
)
);
return super.syntheticSourceSupport();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,34 @@ multiple values in stored annotated_text field with keyword multi-field:
- match:
hits.hits.0._source:
annotated_text: ["world", "hello", "world"]

---
fallback synthetic source:
- do:
indices.create:
index: test
body:
mappings:
_source:
mode: synthetic
properties:
annotated_text:
type: annotated_text
store: false

- do:
index:
index: test
id: 1
refresh: true
body:
annotated_text: ["world", "hello", "world"]

- do:
search:
index: test

- match:
hits.hits.0._source:
annotated_text: ["world", "hello", "world"]

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import org.elasticsearch.index.mapper.MetadataFieldMapper;
import org.elasticsearch.index.mapper.NumberFieldMapper.NumberFieldType;
import org.elasticsearch.index.mapper.NumberFieldMapper.NumberType;
import org.elasticsearch.index.mapper.SourceLoader;
import org.elasticsearch.index.mapper.ValueFetcher;
import org.elasticsearch.index.query.SearchExecutionContext;

Expand Down Expand Up @@ -97,9 +96,4 @@ public void postParse(DocumentParserContext context) {
public FieldMapper.Builder getMergeBuilder() {
return new Builder().init(this);
}

@Override
public SourceLoader.SyntheticFieldLoader syntheticFieldLoader() {
return SourceLoader.SyntheticFieldLoader.NOTHING;
}
}
Loading

0 comments on commit 99e83c3

Please sign in to comment.