@Test public void testLatLonArrayArrayStored() throws Exception { String mapping = XContentFactory.jsonBuilder() .startObject() .startObject("type") .startObject("properties") .startObject("point") .field("type", "geo_point") .field("store", "yes") .endObject() .endObject() .endObject() .endObject() .string(); XContentDocumentMapper defaultMapper = XContentMapperTests.newParser().parse(mapping); ParsedDocument doc = defaultMapper.parse( "type", "1", XContentFactory.jsonBuilder() .startObject() .startArray("point") .startArray() .value(1.2) .value(1.3) .endArray() .startArray() .value(1.4) .value(1.5) .endArray() .endArray() .endObject() .copiedBytes()); assertThat(doc.doc().getFields("point.lat").length, equalTo(2)); assertThat(doc.doc().getFields("point.lon").length, equalTo(2)); assertThat( doc.doc().getFields("point.lat")[0].getBinaryValue(), equalTo(Numbers.doubleToBytes(1.2))); assertThat( doc.doc().getFields("point.lon")[0].getBinaryValue(), equalTo(Numbers.doubleToBytes(1.3))); assertThat( doc.doc().getFields("point.lat")[1].getBinaryValue(), equalTo(Numbers.doubleToBytes(1.4))); assertThat( doc.doc().getFields("point.lon")[1].getBinaryValue(), equalTo(Numbers.doubleToBytes(1.5))); assertThat(doc.doc().getField("point.geohash"), nullValue()); }
@Override public Short value(Fieldable field) { byte[] value = field.getBinaryValue(); if (value == null) { return null; } return Numbers.bytesToShort(value); }
@Override public Integer value(Object value) { if (value == null) { return null; } if (value instanceof Number) { return ((Number) value).intValue(); } if (value instanceof BytesRef) { return Numbers.bytesToInt((BytesRef) value); } return Integer.parseInt(value.toString()); }
@Override public Float value(Object value) { if (value == null) { return null; } if (value instanceof Number) { return ((Number) value).floatValue(); } if (value instanceof BytesRef) { return Numbers.bytesToFloat((BytesRef) value); } return Float.parseFloat(value.toString()); }
@Override public Long value(Object value) { if (value == null) { return null; } if (value instanceof Number) { return ((Number) value).longValue(); } if (value instanceof BytesRef) { return Numbers.bytesToLong((BytesRef) value); } return ipToLong(value.toString()); }
@Override public Double value(Object value) { if (value == null) { return null; } if (value instanceof Number) { return ((Number) value).doubleValue(); } if (value instanceof BytesRef) { return Numbers.bytesToDouble((BytesRef) value); } return Double.parseDouble(value.toString()); }
@Override public Short value(Object value) { if (value == null) { return null; } if (value instanceof Number) { return ((Number) value).shortValue(); } if (value instanceof BytesRef) { return Numbers.bytesToShort((BytesRef) value); } return Short.parseShort(value.toString()); }
public CustomShortNumericField(NumberFieldMapper mapper, short number) { super(mapper, mapper.stored() ? Numbers.shortToBytes(number) : null); this.mapper = mapper; this.number = number; }