Package org.elasticsearch.common.unit.DistanceUnit

Examples of org.elasticsearch.common.unit.DistanceUnit.Distance


        @Override
        public IndexFieldData<?> build(Index index, @IndexSettings Settings indexSettings, FieldMapper<?> mapper, IndexFieldDataCache cache,
                                       CircuitBreakerService breakerService, MapperService mapperService) {
            FieldDataType type = mapper.fieldDataType();
            final String precisionAsString = type.getSettings().get(PRECISION_KEY);
            final Distance precision;
            if (precisionAsString != null) {
                precision = Distance.parseDistance(precisionAsString);
            } else {
                precision = DEFAULT_PRECISION_VALUE;
            }
View Full Code Here


    public void test() {
        for (int i = 0; i < 10000; ++i) {
            final double lat = randomDouble() * 180 - 90;
            final double lon = randomDouble() * 360 - 180;
            final Distance precision = new Distance(1+(randomDouble() * 9), randomFrom(Arrays.asList(DistanceUnit.MILLIMETERS, DistanceUnit.METERS, DistanceUnit.KILOMETERS)));
            final GeoPointFieldMapper.Encoding encoding = GeoPointFieldMapper.Encoding.of(precision);
            assertThat(encoding.precision().convert(DistanceUnit.METERS).value, lessThanOrEqualTo(precision.convert(DistanceUnit.METERS).value));
            final GeoPoint geoPoint = encoding.decode(encoding.encodeCoordinate(lat), encoding.encodeCoordinate(lon), new GeoPoint());
            final double error = GeoDistance.PLANE.calculate(lat, lon, geoPoint.lat(), geoPoint.lon(), DistanceUnit.METERS);
            assertThat(error, lessThanOrEqualTo(precision.convert(DistanceUnit.METERS).value));
        }
    }
View Full Code Here

                refreshReader();
            }
        }
        LeafReaderContext context = refreshReader();
        Map<FieldDataType, Type> typeMap = new HashMap<>();
        final Distance precision = new Distance(1, randomFrom(DistanceUnit.values()));
        typeMap.put(new FieldDataType("geo_point", ImmutableSettings.builder().put("format", "array")), Type.GeoPoint);
        typeMap.put(new FieldDataType("geo_point", ImmutableSettings.builder().put("format", "compressed").put("precision", precision)), Type.GeoPoint);
        typeMap.put(new FieldDataType("geo_point", ImmutableSettings.builder().put("format", "doc_values")), Type.GeoPoint);

        ArrayList<Entry<FieldDataType, Type>> list = new ArrayList<>(typeMap.entrySet());
View Full Code Here

    }

    private static boolean contains(GeoPoint point, List<GeoPoint> set, Distance precision) {
        for (GeoPoint r : set) {
            final double distance = GeoDistance.PLANE.calculate(point.getLat(), point.getLon(), r.getLat(), r.getLon(), DistanceUnit.METERS);
            if (new Distance(distance, DistanceUnit.METERS).compareTo(precision) <= 0) {
                return true;
            }
        }
        return false;
    }
View Full Code Here

                        .endObject()
                    .endObject()
                .endObject()
                .endObject()).get());
        ensureYellow();
        assertPrecision(new Distance(2, DistanceUnit.MILLIMETERS));

        assertAcked(client().admin().indices().preparePutMapping("test").setType("type1").setSource(XContentFactory.jsonBuilder().startObject()
                .startObject("type1")
                .startObject("properties")
                    .startObject("pin")
                        .field("type", "geo_point")
                            .startObject("fielddata")
                                .field("format", "compressed")
                                .field("precision", "11m")
                            .endObject()
                    .endObject()
                .endObject()
            .endObject()
            .endObject()).get());

        assertPrecision(new Distance(11, DistanceUnit.METERS));
    }
View Full Code Here

        ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings = client().admin().indices().getMappings(new GetMappingsRequest().indices("test").types("type1")).actionGet().getMappings();
        assertNotNull(mappings);
        Map<String, ?> properties = (Map<String, ?>) mappings.get("test").get("type1").getSourceAsMap().get("properties");
        Map<String, ?> pinProperties = (Map<String, ?>) properties.get("pin");
        Map<String, ?> pinFieldData = (Map<String, ?>) pinProperties.get("fielddata");
        Distance precision = Distance.parseDistance(pinFieldData.get("precision").toString());
        assertEquals(expected, precision);
    }
View Full Code Here

TOP

Related Classes of org.elasticsearch.common.unit.DistanceUnit.Distance

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.