From 734e656a913b1e4185e5fa40be1fde4e9352b1e0 Mon Sep 17 00:00:00 2001 From: Britta Weber Date: Fri, 18 Jul 2014 16:02:14 +0200 Subject: [PATCH] Make _all field accessible with GET GET only returned null even when stored if requested with GET like this: `curl -XGET "http://localhost:9200/test/test/1?fields=_all"` Instead, it should simply behave like a String field and return the concatenated fields as String. closes #6924 --- .../index/mapper/internal/AllFieldMapper.java | 16 ++++++------- .../org/elasticsearch/get/GetActionTests.java | 24 +++++++++++++++++++ 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/elasticsearch/index/mapper/internal/AllFieldMapper.java b/src/main/java/org/elasticsearch/index/mapper/internal/AllFieldMapper.java index d3b0027153d..ca62dce9e99 100644 --- a/src/main/java/org/elasticsearch/index/mapper/internal/AllFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/internal/AllFieldMapper.java @@ -56,7 +56,7 @@ import static org.elasticsearch.index.mapper.core.TypeParsers.parseField; /** * */ -public class AllFieldMapper extends AbstractFieldMapper implements InternalMapper, RootMapper { +public class AllFieldMapper extends AbstractFieldMapper implements InternalMapper, RootMapper { public interface IncludeInAll extends Mapper { @@ -237,15 +237,13 @@ public class AllFieldMapper extends AbstractFieldMapper implements Interna } return analyzer; } - + @Override - public Void value(Object value) { - return null; - } - - @Override - public Object valueForSearch(Object value) { - return null; + public String value(Object value) { + if (value == null) { + return null; + } + return value.toString(); } @Override diff --git a/src/test/java/org/elasticsearch/get/GetActionTests.java b/src/test/java/org/elasticsearch/get/GetActionTests.java index 1966dc0047f..a2780a9decd 100644 --- a/src/test/java/org/elasticsearch/get/GetActionTests.java +++ b/src/test/java/org/elasticsearch/get/GetActionTests.java @@ -885,4 +885,28 @@ public class GetActionTests extends ElasticsearchIntegrationTest { assertThat(getResponse.getField(field).getValues().get(1).toString(), equalTo("value2")); } + @Test + public void testGet_allField() throws Exception { + prepareCreate("my-index") + .addMapping("my-type1", jsonBuilder() + .startObject() + .startObject("my-type1") + .startObject("_all") + .field("store", true) + .endObject() + .startObject("properties") + .startObject("some_field") + .field("type", "string") + .endObject() + .endObject() + .endObject() + .endObject()) + .get(); + index("my-index", "my-type1", "1", "some_field", "some text"); + refresh(); + + GetResponse getResponse = client().prepareGet("my-index", "my-type1", "1").setFields("_all").get(); + assertNotNull(getResponse.getField("_all").getValue()); + assertThat(getResponse.getField("_all").getValue().toString(), equalTo("some text" + " ")); + } }