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
This commit is contained in:
parent
08f8731b6f
commit
734e656a91
|
@ -56,7 +56,7 @@ import static org.elasticsearch.index.mapper.core.TypeParsers.parseField;
|
|||
/**
|
||||
*
|
||||
*/
|
||||
public class AllFieldMapper extends AbstractFieldMapper<Void> implements InternalMapper, RootMapper {
|
||||
public class AllFieldMapper extends AbstractFieldMapper<String> implements InternalMapper, RootMapper {
|
||||
|
||||
public interface IncludeInAll extends Mapper {
|
||||
|
||||
|
@ -239,13 +239,11 @@ public class AllFieldMapper extends AbstractFieldMapper<Void> implements Interna
|
|||
}
|
||||
|
||||
@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
|
||||
|
|
|
@ -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" + " "));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue