From 266b9bc796be9944c2aaf670c3b5eb467dfff454 Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Fri, 7 Dec 2018 09:57:12 +0100 Subject: [PATCH] Inner hits fail to propagate doc-value format. (#36310) If you pass a doc-value format to inner hits, it gets ignored. --- .../org/elasticsearch/index/query/InnerHitBuilder.java | 2 +- .../elasticsearch/index/query/InnerHitBuilderTests.java | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/org/elasticsearch/index/query/InnerHitBuilder.java b/server/src/main/java/org/elasticsearch/index/query/InnerHitBuilder.java index 894a886182d..bfc786e84f7 100644 --- a/server/src/main/java/org/elasticsearch/index/query/InnerHitBuilder.java +++ b/server/src/main/java/org/elasticsearch/index/query/InnerHitBuilder.java @@ -371,7 +371,7 @@ public final class InnerHitBuilder implements Writeable, ToXContentObject { if (docValueFields == null) { docValueFields = new ArrayList<>(); } - docValueFields.add(new FieldAndFormat(field, null)); + docValueFields.add(new FieldAndFormat(field, format)); return this; } diff --git a/server/src/test/java/org/elasticsearch/index/query/InnerHitBuilderTests.java b/server/src/test/java/org/elasticsearch/index/query/InnerHitBuilderTests.java index 95a91e1668c..5c76c77b5c8 100644 --- a/server/src/test/java/org/elasticsearch/index/query/InnerHitBuilderTests.java +++ b/server/src/test/java/org/elasticsearch/index/query/InnerHitBuilderTests.java @@ -46,6 +46,7 @@ import org.junit.BeforeClass; import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -279,4 +280,12 @@ public class InnerHitBuilderTests extends ESTestCase { return ESTestCase.copyWriteable(original, namedWriteableRegistry, InnerHitBuilder::new); } + public void testSetDocValueFormat() { + InnerHitBuilder innerHit = new InnerHitBuilder(); + innerHit.addDocValueField("foo"); + innerHit.addDocValueField("@timestamp", "epoch_millis"); + assertEquals( + Arrays.asList(new FieldAndFormat("foo", null), new FieldAndFormat("@timestamp", "epoch_millis")), + innerHit.getDocValueFields()); + } }