org.elasticsearch.index.mapper.geo.GeoPointFieldMapper Java Examples

The following examples show how to use org.elasticsearch.index.mapper.geo.GeoPointFieldMapper. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IndicesModule.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
private void registerBuiltInMappers() {
    registerMapper(ByteFieldMapper.CONTENT_TYPE, new ByteFieldMapper.TypeParser());
    registerMapper(ShortFieldMapper.CONTENT_TYPE, new ShortFieldMapper.TypeParser());
    registerMapper(IntegerFieldMapper.CONTENT_TYPE, new IntegerFieldMapper.TypeParser());
    registerMapper(LongFieldMapper.CONTENT_TYPE, new LongFieldMapper.TypeParser());
    registerMapper(FloatFieldMapper.CONTENT_TYPE, new FloatFieldMapper.TypeParser());
    registerMapper(DoubleFieldMapper.CONTENT_TYPE, new DoubleFieldMapper.TypeParser());
    registerMapper(BooleanFieldMapper.CONTENT_TYPE, new BooleanFieldMapper.TypeParser());
    registerMapper(BinaryFieldMapper.CONTENT_TYPE, new BinaryFieldMapper.TypeParser());
    registerMapper(DateFieldMapper.CONTENT_TYPE, new DateFieldMapper.TypeParser());
    registerMapper(IpFieldMapper.CONTENT_TYPE, new IpFieldMapper.TypeParser());
    registerMapper(StringFieldMapper.CONTENT_TYPE, new StringFieldMapper.TypeParser());
    registerMapper(TokenCountFieldMapper.CONTENT_TYPE, new TokenCountFieldMapper.TypeParser());
    registerMapper(ObjectMapper.CONTENT_TYPE, new ObjectMapper.TypeParser());
    registerMapper(ObjectMapper.NESTED_CONTENT_TYPE, new ObjectMapper.TypeParser());
    registerMapper(TypeParsers.MULTI_FIELD_CONTENT_TYPE, TypeParsers.multiFieldConverterTypeParser);
    registerMapper(CompletionFieldMapper.CONTENT_TYPE, new CompletionFieldMapper.TypeParser());
    registerMapper(GeoPointFieldMapper.CONTENT_TYPE, new GeoPointFieldMapper.TypeParser());

    if (ShapesAvailability.JTS_AVAILABLE) {
        registerMapper(GeoShapeFieldMapper.CONTENT_TYPE, new GeoShapeFieldMapper.TypeParser());
    }
}
 
Example #2
Source File: DecayFunctionParser.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
private AbstractDistanceScoreFunction parseVariable(String fieldName, XContentParser parser, QueryParseContext parseContext, MultiValueMode mode) throws IOException {

        // now, the field must exist, else we cannot read the value for
        // the doc later
        MappedFieldType fieldType = parseContext.fieldMapper(fieldName);
        if (fieldType == null) {
            throw new QueryParsingException(parseContext, "unknown field [{}]", fieldName);
        }

        // dates and time need special handling
        parser.nextToken();
        if (fieldType instanceof DateFieldMapper.DateFieldType) {
            return parseDateVariable(fieldName, parser, parseContext, (DateFieldMapper.DateFieldType) fieldType, mode);
        } else if (fieldType instanceof GeoPointFieldMapper.GeoPointFieldType) {
            return parseGeoVariable(fieldName, parser, parseContext, (GeoPointFieldMapper.GeoPointFieldType) fieldType, mode);
        } else if (fieldType instanceof NumberFieldMapper.NumberFieldType) {
            return parseNumberVariable(fieldName, parser, parseContext, (NumberFieldMapper.NumberFieldType) fieldType, mode);
        } else {
            throw new QueryParsingException(parseContext, "field [{}] is of type [{}], but only numeric types are supported.", fieldName, fieldType);
        }
    }
 
Example #3
Source File: LocalWeatherDataMapper.java    From ElasticUtils with MIT License 6 votes vote down vote up
@Override
protected void configureRootObjectBuilder(RootObjectMapper.Builder builder) {
    builder
            .add(new DateFieldMapper.Builder("dateTime"))
            .add(new FloatFieldMapper.Builder("temperature"))
            .add(new FloatFieldMapper.Builder("windSpeed"))
            .add(new FloatFieldMapper.Builder("stationPressure"))
            .add(new StringFieldMapper.Builder("skyCondition"))
            .add(new ObjectMapper.Builder("station")
                    .add(new StringFieldMapper.Builder("wban"))
                    .add(new StringFieldMapper.Builder("name"))
                    .add(new StringFieldMapper.Builder("state"))
                    .add(new StringFieldMapper.Builder("location"))
                    .add(new GeoPointFieldMapper.Builder("coordinates")
                            .enableLatLon(true)
                            .enableGeoHash(false))
                    .nested(ObjectMapper.Nested.newNested(true, false)));
}
 
Example #4
Source File: LocalWeatherDataMapper.java    From JavaElasticSearchExperiment with MIT License 6 votes vote down vote up
@Override
protected void configure(RootObjectMapper.Builder builder) {
    builder
            .add(new DateFieldMapper.Builder("dateTime"))
            .add(new FloatFieldMapper.Builder("temperature"))
            .add(new FloatFieldMapper.Builder("windSpeed"))
            .add(new FloatFieldMapper.Builder("stationPressure"))
            .add(new StringFieldMapper.Builder("skyCondition"))
            .add(new ObjectMapper.Builder("station")
                    .add(new StringFieldMapper.Builder("wban"))
                    .add(new StringFieldMapper.Builder("name"))
                    .add(new StringFieldMapper.Builder("state"))
                    .add(new StringFieldMapper.Builder("location"))
                    .add(new GeoPointFieldMapper.Builder("coordinates")
                            .enableLatLon(true)
                            .enableGeoHash(false))
                    .nested(ObjectMapper.Nested.newNested(true, false)));
}
 
Example #5
Source File: MapperTestUtils.java    From elasticsearch-analysis-baseform with Apache License 2.0 6 votes vote down vote up
private static Map<String, Mapper.TypeParser> registerBuiltInMappers() {
    Map<String, Mapper.TypeParser> mapperParsers = new LinkedHashMap<>();
    mapperParsers.put(ByteFieldMapper.CONTENT_TYPE, new ByteFieldMapper.TypeParser());
    mapperParsers.put(ShortFieldMapper.CONTENT_TYPE, new ShortFieldMapper.TypeParser());
    mapperParsers.put(IntegerFieldMapper.CONTENT_TYPE, new IntegerFieldMapper.TypeParser());
    mapperParsers.put(LongFieldMapper.CONTENT_TYPE, new LongFieldMapper.TypeParser());
    mapperParsers.put(FloatFieldMapper.CONTENT_TYPE, new FloatFieldMapper.TypeParser());
    mapperParsers.put(DoubleFieldMapper.CONTENT_TYPE, new DoubleFieldMapper.TypeParser());
    mapperParsers.put(BooleanFieldMapper.CONTENT_TYPE, new BooleanFieldMapper.TypeParser());
    mapperParsers.put(BinaryFieldMapper.CONTENT_TYPE, new BinaryFieldMapper.TypeParser());
    mapperParsers.put(DateFieldMapper.CONTENT_TYPE, new DateFieldMapper.TypeParser());
    mapperParsers.put(IpFieldMapper.CONTENT_TYPE, new IpFieldMapper.TypeParser());
    mapperParsers.put(StringFieldMapper.CONTENT_TYPE, new StringFieldMapper.TypeParser());
    mapperParsers.put(TokenCountFieldMapper.CONTENT_TYPE, new TokenCountFieldMapper.TypeParser());
    mapperParsers.put(ObjectMapper.CONTENT_TYPE, new ObjectMapper.TypeParser());
    mapperParsers.put(ObjectMapper.NESTED_CONTENT_TYPE, new ObjectMapper.TypeParser());
    mapperParsers.put(TypeParsers.MULTI_FIELD_CONTENT_TYPE, TypeParsers.multiFieldConverterTypeParser);
    mapperParsers.put(CompletionFieldMapper.CONTENT_TYPE, new CompletionFieldMapper.TypeParser());
    mapperParsers.put(GeoPointFieldMapper.CONTENT_TYPE, new GeoPointFieldMapper.TypeParser());
    return mapperParsers;
}
 
Example #6
Source File: LuceneQueryBuilder.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private Query getQuery(Function inner, Context context) {
    RefLiteralPair innerPair = new RefLiteralPair(inner);
    if (!innerPair.isValid()) {
        return null;
    }
    if (innerPair.reference().valueType().equals(DataTypes.GEO_SHAPE)) {
        // we have within('POINT(0 0)', shape_column)
        return genericFunctionFilter(inner, context);
    }
    GeoPointFieldMapper.GeoPointFieldType geoPointFieldType = getGeoPointFieldType(
            innerPair.reference().ident().columnIdent().fqn(),
            context.mapperService);

    Map<String, Object> geoJSON = (Map<String, Object>) innerPair.input().value();
    Shape shape = GeoJSONUtils.map2Shape(geoJSON);
    Geometry geometry = JtsSpatialContext.GEO.getGeometryFrom(shape);
    IndexGeoPointFieldData fieldData = context.fieldDataService.getForField(geoPointFieldType);
    if (geometry.isRectangle()) {
        Rectangle boundingBox = shape.getBoundingBox();
        return new InMemoryGeoBoundingBoxQuery(
                new GeoPoint(boundingBox.getMaxY(), boundingBox.getMinX()),
                new GeoPoint(boundingBox.getMinY(), boundingBox.getMaxX()),
                fieldData
        );
    } else {
        Coordinate[] coordinates = geometry.getCoordinates();
        GeoPoint[] points = new GeoPoint[coordinates.length];
        for (int i = 0; i < coordinates.length; i++) {
            Coordinate coordinate = coordinates[i];
            points[i] = new GeoPoint(coordinate.y, coordinate.x);
        }
        return new GeoPolygonQuery(fieldData, points);
    }
}
 
Example #7
Source File: LuceneQueryBuilder.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private static GeoPointFieldMapper.GeoPointFieldType getGeoPointFieldType(String fieldName, MapperService mapperService) {
    MappedFieldType fieldType =  mapperService.smartNameFieldType(fieldName);
    if (fieldType == null) {
        throw new IllegalArgumentException(String.format("column \"%s\" doesn't exist", fieldName));
    }
    if (!(fieldType instanceof GeoPointFieldMapper.GeoPointFieldType)) {
        throw new IllegalArgumentException(String.format("column \"%s\" isn't of type geo_point", fieldName));
    }
    return (GeoPointFieldMapper.GeoPointFieldType) fieldType;
}
 
Example #8
Source File: DecayFunctionParser.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private AbstractDistanceScoreFunction parseGeoVariable(String fieldName, XContentParser parser, QueryParseContext parseContext,
        GeoPointFieldMapper.GeoPointFieldType fieldType, MultiValueMode mode) throws IOException {
    XContentParser.Token token;
    String parameterName = null;
    GeoPoint origin = new GeoPoint();
    String scaleString = null;
    String offsetString = "0km";
    double decay = 0.5;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            parameterName = parser.currentName();
        } else if (parameterName.equals(DecayFunctionBuilder.SCALE)) {
            scaleString = parser.text();
        } else if (parameterName.equals(DecayFunctionBuilder.ORIGIN)) {
            origin = GeoUtils.parseGeoPoint(parser);
        } else if (parameterName.equals(DecayFunctionBuilder.DECAY)) {
            decay = parser.doubleValue();
        } else if (parameterName.equals(DecayFunctionBuilder.OFFSET)) {
            offsetString = parser.text();
        } else {
            throw new ElasticsearchParseException("parameter [{}] not supported!", parameterName);
        }
    }
    if (origin == null || scaleString == null) {
        throw new ElasticsearchParseException("[{}] and [{}] must be set for geo fields.", DecayFunctionBuilder.ORIGIN, DecayFunctionBuilder.SCALE);
    }
    double scale = DistanceUnit.DEFAULT.parse(scaleString, DistanceUnit.DEFAULT);
    double offset = DistanceUnit.DEFAULT.parse(offsetString, DistanceUnit.DEFAULT);
    IndexGeoPointFieldData indexFieldData = parseContext.getForField(fieldType);
    return new GeoFieldDataScoreFunction(origin, scale, decay, offset, getDecayFunction(), indexFieldData, mode);

}