Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion x-pack/plugin/runtime-fields/qa/rest/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ yamlRestTest {
'search/115_multiple_field_collapsing/two levels fields collapsing', // Broken. Gotta fix.
'field_caps/30_filter/Field caps with index filter', // We don't support filtering field caps on runtime fields. What should we do?
'search.aggregation/10_histogram/*', // runtime_script doesn't support sub-fields. Maybe it should?
'search/10_source_filtering/docvalue_fields with explicit format',
'search.aggregation/200_top_hits_metric/top_hits aggregation with sequence numbers',
'search.aggregation/200_top_hits_metric/top_hits aggregation with nested documents',
'search/140_pre_filter_search_shards/pre_filter_shard_size with shards that have no hit',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.elasticsearch.index.mapper.NumberFieldMapper.NumberType;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.script.Script;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.lookup.SearchLookup;
import org.elasticsearch.xpack.runtimefields.DoubleScriptFieldScript;
import org.elasticsearch.xpack.runtimefields.fielddata.ScriptDoubleFieldData;
Expand Down Expand Up @@ -46,6 +47,17 @@ public Object valueForDisplay(Object value) {
return value; // These should come back as a Double
}

@Override
public DocValueFormat docValueFormat(String format, ZoneId timeZone) {
if (timeZone != null) {
throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] does not support custom time zones");
}
if (format == null) {
return DocValueFormat.RAW;
}
return new DocValueFormat.Decimal(format);
}

@Override
public ScriptDoubleFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName, Supplier<SearchLookup> searchLookup) {
return new ScriptDoubleFieldData.Builder(name(), leafFactory(searchLookup.get()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.elasticsearch.index.mapper.NumberFieldMapper.NumberType;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.script.Script;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.lookup.SearchLookup;
import org.elasticsearch.xpack.runtimefields.LongScriptFieldScript;
import org.elasticsearch.xpack.runtimefields.fielddata.ScriptLongFieldData;
Expand Down Expand Up @@ -46,6 +47,17 @@ public Object valueForDisplay(Object value) {
return value; // These should come back as a Long
}

@Override
public DocValueFormat docValueFormat(String format, ZoneId timeZone) {
if (timeZone != null) {
throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] does not support custom time zones");
}
if (format == null) {
return DocValueFormat.RAW;
}
return new DocValueFormat.Decimal(format);
}

@Override
public ScriptLongFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName, Supplier<SearchLookup> searchLookup) {
return new ScriptLongFieldData.Builder(name(), leafFactory(searchLookup.get()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@
import static org.hamcrest.Matchers.equalTo;

public class ScriptDoubleMappedFieldTypeTests extends AbstractNonTextScriptMappedFieldTypeTestCase {
public void testFormat() throws IOException {
assertThat(simpleMappedFieldType().docValueFormat("#.0", null).format(1), equalTo("1.0"));
assertThat(simpleMappedFieldType().docValueFormat("#.0", null).format(1.2), equalTo("1.2"));
assertThat(simpleMappedFieldType().docValueFormat("#,##0.##", null).format(11), equalTo("11"));
assertThat(simpleMappedFieldType().docValueFormat("#,##0.##", null).format(1123), equalTo("1,123"));
assertThat(simpleMappedFieldType().docValueFormat("#,##0.00", null).format(1123), equalTo("1,123.00"));
assertThat(simpleMappedFieldType().docValueFormat("#,##0.00", null).format(1123.1), equalTo("1,123.10"));
}

@Override
public void testDocValues() throws IOException {
try (Directory directory = newDirectory(); RandomIndexWriter iw = new RandomIndexWriter(random(), directory)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@
import static org.hamcrest.Matchers.equalTo;

public class ScriptLongMappedFieldTypeTests extends AbstractNonTextScriptMappedFieldTypeTestCase {
public void testFormat() throws IOException {
assertThat(simpleMappedFieldType().docValueFormat("#.0", null).format(1), equalTo("1.0"));
assertThat(simpleMappedFieldType().docValueFormat("#,##0.##", null).format(11), equalTo("11"));
assertThat(simpleMappedFieldType().docValueFormat("#,##0.##", null).format(1123), equalTo("1,123"));
}

@Override
public void testDocValues() throws IOException {
try (Directory directory = newDirectory(); RandomIndexWriter iw = new RandomIndexWriter(random(), directory)) {
Expand Down