GeoPointFieldMapper.java 951 B

1234567891011121314151617181920212223242526272829303132
  1. package org.es.mapping.mapper;
  2. import org.elasticsearch.common.xcontent.XContentBuilder;
  3. import org.es.mapping.annotations.fieldtype.GeoPointField;
  4. import org.es.mapping.bean.GeoPoint;
  5. import java.io.IOException;
  6. import java.lang.reflect.Field;
  7. public class GeoPointFieldMapper {
  8. public static boolean isValidGeoPointFieldType(Field field) {
  9. Class<?> fieldClass = field.getType();
  10. if (!field.isAnnotationPresent(GeoPointField.class)) {
  11. return false;
  12. }
  13. return String.class == fieldClass || fieldClass == GeoPoint.class;
  14. }
  15. public static void mapDataType(XContentBuilder mappingBuilder, Field field) throws IOException {
  16. if (!isValidGeoPointFieldType(field)) {
  17. throw new IllegalArgumentException(
  18. String.format("field type[%s] is invalid type of percolator.", field.getType()));
  19. }
  20. mappingBuilder.field("type", "geo_point");
  21. }
  22. }