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

Allow GET access to _all field (return value was always null before) #6924

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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" + " "));
}
}