Skip to content

Commit

Permalink
Make _all field accessible with GET
Browse files Browse the repository at this point in the history
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
  • Loading branch information
brwe committed Jul 23, 2014
1 parent 3c57800 commit c8f01dc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
Expand Up @@ -56,7 +56,7 @@
/**
*
*/
public class AllFieldMapper extends AbstractFieldMapper<Void> implements InternalMapper, RootMapper {
public class AllFieldMapper extends AbstractFieldMapper<String> implements InternalMapper, RootMapper {

public interface IncludeInAll extends Mapper {

Expand Down Expand Up @@ -237,15 +237,13 @@ private Analyzer findAnalyzer(ParseContext context) {
}
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
Expand Down
24 changes: 24 additions & 0 deletions src/test/java/org/elasticsearch/get/GetActionTests.java
Expand Up @@ -885,4 +885,28 @@ public void testGetFields_complexField() throws Exception {
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" + " "));
}
}

0 comments on commit c8f01dc

Please sign in to comment.