Skip to content
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

Synthetic source #85649

Merged
merged 54 commits into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
b324d95
Keyword
nik9000 Mar 30, 2022
1570af9
Numbers
nik9000 Mar 30, 2022
16f2250
Fetch
nik9000 Mar 30, 2022
571b1b6
Multi field tests
nik9000 Mar 31, 2022
63c3c73
Text
nik9000 Mar 31, 2022
3c07737
Scaled float
nik9000 Mar 31, 2022
9185bae
ip
nik9000 Mar 31, 2022
4a1e015
Wip2
nik9000 Apr 1, 2022
e872b47
Sorted
nik9000 Apr 1, 2022
84c7bde
nested and parent/child
nik9000 Apr 1, 2022
0a24a1d
Fixup
nik9000 Apr 1, 2022
cf66fd7
Merge branch 'master' into synthetic_source_1
nik9000 Apr 1, 2022
62d5ba2
More paranoia
nik9000 Apr 1, 2022
fe59f93
Merge branch 'master' into synthetic_source_1
nik9000 Apr 1, 2022
da6daaf
Malformed
nik9000 Apr 4, 2022
eef696d
Tests
nik9000 Apr 5, 2022
01139af
fix test
nik9000 Apr 5, 2022
bc343eb
Merge branch 'master' into synthetic_source_1
nik9000 Apr 5, 2022
d11e7af
Update skip after versoin bump
nik9000 Apr 5, 2022
85b9921
reindex
nik9000 Apr 5, 2022
fb94d47
rolling upgrade
nik9000 Apr 5, 2022
0413544
CCR
nik9000 Apr 5, 2022
b98424b
No copy to
nik9000 Apr 6, 2022
1548dcd
Random scaling factor in float tests
nik9000 Apr 6, 2022
b3986f0
Moar tests
nik9000 Apr 6, 2022
66d1df4
Force override
nik9000 Apr 6, 2022
4a77ee4
Moar tests
nik9000 Apr 18, 2022
b33e91d
Tests for geo_point
nik9000 Apr 18, 2022
ea3c11b
Better tests for ip
nik9000 Apr 18, 2022
1c65e90
Scaled float now
nik9000 Apr 18, 2022
2a18915
Cleanup
nik9000 Apr 18, 2022
789ce65
fromat
nik9000 Apr 18, 2022
c8164f8
Merge branch 'master' into synthetic_source_1
nik9000 Apr 18, 2022
5991084
Merge branch 'master' into synthetic_source_1
nik9000 Apr 18, 2022
f903892
Fixup
nik9000 Apr 18, 2022
21ef0f1
Merge branch 'master' into synthetic_source_1
nik9000 Apr 19, 2022
fca2ea8
Fixup
nik9000 Apr 25, 2022
8005315
Round trip
nik9000 Apr 25, 2022
1451ee7
Merge branch 'master' into synthetic_source_1
nik9000 Apr 25, 2022
6a3078c
Update docs/changelog/85649.yaml
nik9000 Apr 25, 2022
fb8b419
Merge branch 'master' into synthetic_source_1
nik9000 Apr 26, 2022
adfc9a3
Spotless
nik9000 Apr 26, 2022
6065e29
Merge branch 'master' into synthetic_source_1
nik9000 Apr 28, 2022
2ee0741
Fixup
nik9000 May 2, 2022
41987af
Merge branch 'master' into synthetic_source_1
nik9000 May 4, 2022
6c94982
Merge branch 'master' into synthetic_source_1
nik9000 May 4, 2022
da56116
Turn off round trips for certain things
nik9000 May 4, 2022
f4a838a
works now!
nik9000 May 5, 2022
9e936f4
Tests passing!
nik9000 May 5, 2022
df6c852
Merge branch 'master' into synthetic_source_1
nik9000 May 5, 2022
314fe1d
Merge branch 'master' into synthetic_source_1
nik9000 May 6, 2022
17d5d56
Change tests
nik9000 May 7, 2022
9bf5425
Merge branch 'master' into synthetic_source_1
nik9000 May 9, 2022
03239bd
Remove empty buddy
nik9000 May 9, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/85649.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 85649
summary: Synthetic source
area: Mapping
type: feature
issues: []
228 changes: 116 additions & 112 deletions docs/reference/search/profile.asciidoc

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.elasticsearch.test.VersionUtils;
import org.elasticsearch.xcontent.ToXContent;
import org.elasticsearch.xcontent.XContentBuilder;
import org.junit.AssumptionViolatedException;

import java.io.IOException;
import java.util.Collection;
Expand Down Expand Up @@ -677,4 +678,14 @@ protected Object generateRandomInputValue(MappedFieldType ft) {
assumeFalse("Test implemented in a follow up", true);
return null;
}

@Override
protected SyntheticSourceSupport syntheticSourceSupport() {
throw new AssumptionViolatedException("not supported");
}

@Override
protected IngestScriptSupport ingestScriptSupport() {
throw new AssumptionViolatedException("not supported");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.elasticsearch.index.mapper.MapperBuilderContext;
import org.elasticsearch.index.mapper.NumberFieldMapper;
import org.elasticsearch.index.mapper.SimpleMappedFieldType;
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 @@ -349,6 +350,20 @@ private double scale(Object input) {
public TimeSeriesParams.MetricType getMetricType() {
return metricType;
}

@Override
public String toString() {
StringBuilder b = new StringBuilder();
b.append("ScaledFloatFieldType[").append(scalingFactor);
if (nullValue != null) {
b.append(", nullValue=").append(nullValue);
;
}
if (metricType != null) {
b.append(", metricType=").append(metricType);
}
return b.append("]").toString();
}
}

private final Explicit<Boolean> ignoreMalformed;
Expand Down Expand Up @@ -641,4 +656,29 @@ public Object nextValue() throws IOException {
};
}
}

@Override
public SourceLoader.SyntheticFieldLoader syntheticFieldLoader() {
if (hasDocValues == false) {
throw new IllegalArgumentException(
"field [" + name() + "] of type [" + typeName() + "] doesn't support synthetic source because it doesn't have doc values"
);
}
if (ignoreMalformed.value()) {
throw new IllegalArgumentException(
"field [" + name() + "] of type [" + typeName() + "] doesn't support synthetic source because it ignores malformed numbers"
);
}
if (copyTo.copyToFields().isEmpty() != true) {
throw new IllegalArgumentException(
"field [" + name() + "] of type [" + typeName() + "] doesn't support synthetic source because it declares copy_to"
);
}
return new NumberFieldMapper.NumericSyntheticFieldLoader(name(), simpleName()) {
@Override
protected void loadNextValue(XContentBuilder b, long value) throws IOException {
b.value(value / scalingFactor);
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.XContentFactory;
import org.hamcrest.Matchers;
import org.junit.AssumptionViolatedException;

import java.io.IOException;
import java.util.Collection;
Expand Down Expand Up @@ -162,4 +163,14 @@ protected Object generateRandomInputValue(MappedFieldType ft) {
protected void randomFetchTestFieldConfig(XContentBuilder b) throws IOException {
assumeFalse("We don't have a way to assert things here", true);
}

@Override
protected SyntheticSourceSupport syntheticSourceSupport() {
throw new AssumptionViolatedException("not supported");
}

@Override
protected IngestScriptSupport ingestScriptSupport() {
throw new AssumptionViolatedException("not supported");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.elasticsearch.index.mapper.ParsedDocument;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.xcontent.XContentBuilder;
import org.junit.AssumptionViolatedException;

import java.io.IOException;
import java.util.Arrays;
Expand Down Expand Up @@ -157,4 +158,14 @@ protected Object generateRandomInputValue(MappedFieldType ft) {
assumeFalse("Test implemented in a follow up", true);
return null;
}

@Override
protected SyntheticSourceSupport syntheticSourceSupport() {
throw new AssumptionViolatedException("not supported");
}

@Override
protected IngestScriptSupport ingestScriptSupport() {
throw new AssumptionViolatedException("not supported");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.xcontent.XContentBuilder;
import org.hamcrest.Matchers;
import org.junit.AssumptionViolatedException;

import java.io.IOException;
import java.util.Arrays;
Expand Down Expand Up @@ -176,4 +177,14 @@ protected Object generateRandomInputValue(MappedFieldType ft) {
protected boolean allowsNullValues() {
return false; // TODO should this allow null values?
}

@Override
protected SyntheticSourceSupport syntheticSourceSupport() {
throw new AssumptionViolatedException("not supported");
}

@Override
protected IngestScriptSupport ingestScriptSupport() {
throw new AssumptionViolatedException("not supported");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@

package org.elasticsearch.index.mapper.extras;

import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.DocValuesType;
import org.apache.lucene.index.IndexableField;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.core.Tuple;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.MapperParsingException;
Expand All @@ -23,6 +25,7 @@
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.XContentFactory;
import org.elasticsearch.xcontent.XContentType;
import org.junit.AssumptionViolatedException;

import java.io.IOException;
import java.util.Arrays;
Expand All @@ -31,6 +34,7 @@

import static java.util.Collections.singletonList;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;

public class ScaledFloatFieldMapperTests extends MapperTestCase {

Expand Down Expand Up @@ -349,4 +353,83 @@ protected Object generateRandomInputValue(MappedFieldType ft) {
default -> throw new IllegalArgumentException();
};
}

@Override
protected SyntheticSourceSupport syntheticSourceSupport() {
return new SyntheticSourceSupport() {
private final double scalingFactor = randomDoubleBetween(0, Double.MAX_VALUE, false);
private final Double nullValue = usually() ? null : round(randomValue());

@Override
public SyntheticSourceExample example() {
if (randomBoolean()) {
Tuple<Double, Double> v = generateValue();
return new SyntheticSourceExample(v.v1(), v.v2(), this::mapping);
}
List<Tuple<Double, Double>> values = randomList(1, 5, this::generateValue);
List<Double> in = values.stream().map(Tuple::v1).toList();
List<Double> outList = values.stream().map(Tuple::v2).sorted().toList();
Object out = outList.size() == 1 ? outList.get(0) : outList;
return new SyntheticSourceExample(in, out, this::mapping);
}

private Tuple<Double, Double> generateValue() {
if (nullValue != null && randomBoolean()) {
return Tuple.tuple(null, nullValue);
}
double d = randomValue();
return Tuple.tuple(d, round(d));
}

private double randomValue() {
return randomBoolean() ? randomDoubleBetween(-Double.MAX_VALUE, Double.MAX_VALUE, true) : randomFloat();
}

private double round(double d) {
long encoded = Math.round(d * scalingFactor);
return encoded / scalingFactor;
}

private void mapping(XContentBuilder b) throws IOException {
b.field("type", "scaled_float");
b.field("scaling_factor", scalingFactor);
if (nullValue != null) {
b.field("null_value", nullValue);
}
if (rarely()) {
b.field("index", false);
}
if (rarely()) {
b.field("store", false);
}
}

@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)
),
new SyntheticSourceInvalidExample(
equalTo(
"field [field] of type [scaled_float] doesn't support synthetic source because it ignores malformed numbers"
),
b -> b.field("type", "scaled_float").field("scaling_factor", 10).field("ignore_malformed", true)
)
);
}
};
}

@Override
protected IngestScriptSupport ingestScriptSupport() {
throw new AssumptionViolatedException("not supported");
}

@Override
protected void validateRoundTripReader(String syntheticSource, DirectoryReader reader, DirectoryReader roundTripReader)
throws IOException {
// Intentionally disabled because it doesn't work yet
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import org.elasticsearch.index.search.QueryStringQueryParser;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.xcontent.XContentBuilder;
import org.junit.AssumptionViolatedException;

import java.io.IOException;
import java.util.ArrayList;
Expand Down Expand Up @@ -793,4 +794,14 @@ protected Object generateRandomInputValue(MappedFieldType ft) {
assumeFalse("We don't have doc values or fielddata", true);
return null;
}

@Override
protected SyntheticSourceSupport syntheticSourceSupport() {
throw new AssumptionViolatedException("not supported");
}

@Override
protected IngestScriptSupport ingestScriptSupport() {
throw new AssumptionViolatedException("not supported");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.elasticsearch.index.mapper.SourceToParse;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.xcontent.XContentBuilder;
import org.junit.AssumptionViolatedException;

import java.io.IOException;
import java.util.Arrays;
Expand Down Expand Up @@ -186,4 +187,14 @@ protected String generateRandomInputValue(MappedFieldType ft) {
protected void randomFetchTestFieldConfig(XContentBuilder b) throws IOException {
b.field("type", "token_count").field("analyzer", "standard");
}

@Override
protected SyntheticSourceSupport syntheticSourceSupport() {
throw new AssumptionViolatedException("not supported");
}

@Override
protected IngestScriptSupport ingestScriptSupport() {
throw new AssumptionViolatedException("not supported");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
unsupported:
- skip:
version: " - 8.2.99"
reason: introduced in 8.3.0

- do:
catch: bad_request
indices.create:
index: test
body:
mappings:
_source:
synthetic: true
properties:
join_field:
type: join
relations:
parent: child
Loading