Geo Overhaul (work with multiple locations), closes #414. Change (again) how geo location is stored, not using geohash but explicit double conversion
This commit is contained in:
parent
8a8a4d648a
commit
9077bb6528
|
@ -20,7 +20,6 @@
|
||||||
package org.elasticsearch.index.mapper.xcontent.geo;
|
package org.elasticsearch.index.mapper.xcontent.geo;
|
||||||
|
|
||||||
import org.apache.lucene.index.IndexReader;
|
import org.apache.lucene.index.IndexReader;
|
||||||
import org.elasticsearch.common.lucene.geo.GeoHashUtils;
|
|
||||||
import org.elasticsearch.index.field.data.FieldData;
|
import org.elasticsearch.index.field.data.FieldData;
|
||||||
import org.elasticsearch.index.field.data.FieldDataType;
|
import org.elasticsearch.index.field.data.FieldDataType;
|
||||||
import org.elasticsearch.index.field.data.support.FieldDataLoader;
|
import org.elasticsearch.index.field.data.support.FieldDataLoader;
|
||||||
|
@ -86,8 +85,6 @@ public abstract class GeoPointFieldData extends FieldData<GeoPointDocFieldData>
|
||||||
|
|
||||||
private final ArrayList<GeoPoint> terms = new ArrayList<GeoPoint>();
|
private final ArrayList<GeoPoint> terms = new ArrayList<GeoPoint>();
|
||||||
|
|
||||||
private final double[] latlon = new double[2];
|
|
||||||
|
|
||||||
StringTypeLoader() {
|
StringTypeLoader() {
|
||||||
super();
|
super();
|
||||||
// the first one indicates null value
|
// the first one indicates null value
|
||||||
|
@ -95,8 +92,10 @@ public abstract class GeoPointFieldData extends FieldData<GeoPointDocFieldData>
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void collectTerm(String term) {
|
@Override public void collectTerm(String term) {
|
||||||
GeoHashUtils.decode(term, latlon);
|
int comma = term.indexOf(',');
|
||||||
terms.add(new GeoPoint(latlon[0], latlon[1]));
|
double lat = Double.parseDouble(term.substring(0, comma));
|
||||||
|
double lon = Double.parseDouble(term.substring(comma + 1));
|
||||||
|
terms.add(new GeoPoint(lat, lon));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public GeoPointFieldData buildSingleValue(String field, int[] order) {
|
@Override public GeoPointFieldData buildSingleValue(String field, int[] order) {
|
||||||
|
|
|
@ -72,6 +72,8 @@ public class GeoPointFieldMapper implements XContentMapper, ArrayValueMapperPars
|
||||||
|
|
||||||
private ContentPath.Type pathType = Defaults.PATH_TYPE;
|
private ContentPath.Type pathType = Defaults.PATH_TYPE;
|
||||||
|
|
||||||
|
private boolean enableGeoHash = false;
|
||||||
|
|
||||||
private boolean enableLatLon = false;
|
private boolean enableLatLon = false;
|
||||||
|
|
||||||
private Integer precisionStep;
|
private Integer precisionStep;
|
||||||
|
@ -90,6 +92,11 @@ public class GeoPointFieldMapper implements XContentMapper, ArrayValueMapperPars
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Builder enableGeoHash(boolean enableGeoHash) {
|
||||||
|
this.enableGeoHash = enableGeoHash;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public Builder enableLatLon(boolean enableLatLon) {
|
public Builder enableLatLon(boolean enableLatLon) {
|
||||||
this.enableLatLon = enableLatLon;
|
this.enableLatLon = enableLatLon;
|
||||||
return this;
|
return this;
|
||||||
|
@ -114,7 +121,7 @@ public class GeoPointFieldMapper implements XContentMapper, ArrayValueMapperPars
|
||||||
ContentPath.Type origPathType = context.path().pathType();
|
ContentPath.Type origPathType = context.path().pathType();
|
||||||
context.path().pathType(pathType);
|
context.path().pathType(pathType);
|
||||||
|
|
||||||
GeoHashFieldMapper geohashMapper = new GeoHashFieldMapper.Builder(name)
|
GeoStringFieldMapper geoStringMapper = new GeoStringFieldMapper.Builder(name)
|
||||||
.index(Field.Index.NOT_ANALYZED).omitNorms(true).omitTermFreqAndPositions(true).includeInAll(false).store(store).build(context);
|
.index(Field.Index.NOT_ANALYZED).omitNorms(true).omitTermFreqAndPositions(true).includeInAll(false).store(store).build(context);
|
||||||
|
|
||||||
|
|
||||||
|
@ -132,11 +139,15 @@ public class GeoPointFieldMapper implements XContentMapper, ArrayValueMapperPars
|
||||||
latMapper = (NumberFieldMapper) latMapperBuilder.includeInAll(false).store(store).build(context);
|
latMapper = (NumberFieldMapper) latMapperBuilder.includeInAll(false).store(store).build(context);
|
||||||
lonMapper = (NumberFieldMapper) lonMapperBuilder.includeInAll(false).store(store).build(context);
|
lonMapper = (NumberFieldMapper) lonMapperBuilder.includeInAll(false).store(store).build(context);
|
||||||
}
|
}
|
||||||
|
StringFieldMapper geohashMapper = null;
|
||||||
|
if (enableGeoHash) {
|
||||||
|
geohashMapper = stringField(Names.GEOHASH).index(Field.Index.NOT_ANALYZED).includeInAll(false).omitNorms(true).omitTermFreqAndPositions(true).build(context);
|
||||||
|
}
|
||||||
context.path().remove();
|
context.path().remove();
|
||||||
|
|
||||||
context.path().pathType(origPathType);
|
context.path().pathType(origPathType);
|
||||||
|
|
||||||
return new GeoPointFieldMapper(name, pathType, enableLatLon, precisionStep, precision, latMapper, lonMapper, geohashMapper);
|
return new GeoPointFieldMapper(name, pathType, enableLatLon, enableGeoHash, precisionStep, precision, latMapper, lonMapper, geohashMapper, geoStringMapper);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,9 +164,11 @@ public class GeoPointFieldMapper implements XContentMapper, ArrayValueMapperPars
|
||||||
builder.store(parseStore(name, fieldNode.toString()));
|
builder.store(parseStore(name, fieldNode.toString()));
|
||||||
} else if (fieldName.equals("lat_lon")) {
|
} else if (fieldName.equals("lat_lon")) {
|
||||||
builder.enableLatLon(XContentMapValues.nodeBooleanValue(fieldNode));
|
builder.enableLatLon(XContentMapValues.nodeBooleanValue(fieldNode));
|
||||||
|
} else if (fieldName.equals("geohash")) {
|
||||||
|
builder.enableGeoHash(XContentMapValues.nodeBooleanValue(fieldNode));
|
||||||
} else if (fieldName.equals("precision_step")) {
|
} else if (fieldName.equals("precision_step")) {
|
||||||
builder.precisionStep(XContentMapValues.nodeIntegerValue(fieldNode));
|
builder.precisionStep(XContentMapValues.nodeIntegerValue(fieldNode));
|
||||||
} else if (fieldName.equals("precision")) {
|
} else if (fieldName.equals("geohash_precision")) {
|
||||||
builder.precision(XContentMapValues.nodeIntegerValue(fieldNode));
|
builder.precision(XContentMapValues.nodeIntegerValue(fieldNode));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -169,6 +182,8 @@ public class GeoPointFieldMapper implements XContentMapper, ArrayValueMapperPars
|
||||||
|
|
||||||
private final boolean enableLatLon;
|
private final boolean enableLatLon;
|
||||||
|
|
||||||
|
private final boolean enableGeoHash;
|
||||||
|
|
||||||
private final Integer precisionStep;
|
private final Integer precisionStep;
|
||||||
|
|
||||||
private final int precision;
|
private final int precision;
|
||||||
|
@ -179,16 +194,20 @@ public class GeoPointFieldMapper implements XContentMapper, ArrayValueMapperPars
|
||||||
|
|
||||||
private final StringFieldMapper geohashMapper;
|
private final StringFieldMapper geohashMapper;
|
||||||
|
|
||||||
public GeoPointFieldMapper(String name, ContentPath.Type pathType, boolean enableLatLon, Integer precisionStep, int precision,
|
private final StringFieldMapper geoStringMapper;
|
||||||
NumberFieldMapper latMapper, NumberFieldMapper lonMapper, StringFieldMapper geohashMapper) {
|
|
||||||
|
public GeoPointFieldMapper(String name, ContentPath.Type pathType, boolean enableLatLon, boolean enableGeoHash, Integer precisionStep, int precision,
|
||||||
|
NumberFieldMapper latMapper, NumberFieldMapper lonMapper, StringFieldMapper geohashMapper, StringFieldMapper geoStringMapper) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.pathType = pathType;
|
this.pathType = pathType;
|
||||||
this.enableLatLon = enableLatLon;
|
this.enableLatLon = enableLatLon;
|
||||||
|
this.enableGeoHash = enableGeoHash;
|
||||||
this.precisionStep = precisionStep;
|
this.precisionStep = precisionStep;
|
||||||
this.precision = precision;
|
this.precision = precision;
|
||||||
|
|
||||||
this.latMapper = latMapper;
|
this.latMapper = latMapper;
|
||||||
this.lonMapper = lonMapper;
|
this.lonMapper = lonMapper;
|
||||||
|
this.geoStringMapper = geoStringMapper;
|
||||||
this.geohashMapper = geohashMapper;
|
this.geohashMapper = geohashMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -287,8 +306,12 @@ public class GeoPointFieldMapper implements XContentMapper, ArrayValueMapperPars
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseLatLon(ParseContext context, Double lat, Double lon) throws IOException {
|
private void parseLatLon(ParseContext context, Double lat, Double lon) throws IOException {
|
||||||
|
context.externalValue(lat.toString() + ',' + lon.toString());
|
||||||
|
geoStringMapper.parse(context);
|
||||||
|
if (enableGeoHash) {
|
||||||
context.externalValue(GeoHashUtils.encode(lat, lon, precision));
|
context.externalValue(GeoHashUtils.encode(lat, lon, precision));
|
||||||
geohashMapper.parse(context);
|
geohashMapper.parse(context);
|
||||||
|
}
|
||||||
if (enableLatLon) {
|
if (enableLatLon) {
|
||||||
context.externalValue(lat);
|
context.externalValue(lat);
|
||||||
latMapper.parse(context);
|
latMapper.parse(context);
|
||||||
|
@ -298,10 +321,14 @@ public class GeoPointFieldMapper implements XContentMapper, ArrayValueMapperPars
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseGeohash(ParseContext context, String geohash) throws IOException {
|
private void parseGeohash(ParseContext context, String geohash) throws IOException {
|
||||||
|
double[] values = GeoHashUtils.decode(geohash);
|
||||||
|
context.externalValue(Double.toString(values[0]) + ',' + Double.toString(values[1]));
|
||||||
|
geoStringMapper.parse(context);
|
||||||
|
if (enableGeoHash) {
|
||||||
context.externalValue(geohash);
|
context.externalValue(geohash);
|
||||||
geohashMapper.parse(context);
|
geohashMapper.parse(context);
|
||||||
|
}
|
||||||
if (enableLatLon) {
|
if (enableLatLon) {
|
||||||
double[] values = GeoHashUtils.decode(geohash);
|
|
||||||
context.externalValue(values[0]);
|
context.externalValue(values[0]);
|
||||||
latMapper.parse(context);
|
latMapper.parse(context);
|
||||||
context.externalValue(values[1]);
|
context.externalValue(values[1]);
|
||||||
|
@ -314,7 +341,10 @@ public class GeoPointFieldMapper implements XContentMapper, ArrayValueMapperPars
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void traverse(FieldMapperListener fieldMapperListener) {
|
@Override public void traverse(FieldMapperListener fieldMapperListener) {
|
||||||
|
geoStringMapper.traverse(fieldMapperListener);
|
||||||
|
if (enableGeoHash) {
|
||||||
geohashMapper.traverse(fieldMapperListener);
|
geohashMapper.traverse(fieldMapperListener);
|
||||||
|
}
|
||||||
if (enableLatLon) {
|
if (enableLatLon) {
|
||||||
latMapper.traverse(fieldMapperListener);
|
latMapper.traverse(fieldMapperListener);
|
||||||
lonMapper.traverse(fieldMapperListener);
|
lonMapper.traverse(fieldMapperListener);
|
||||||
|
@ -326,12 +356,9 @@ public class GeoPointFieldMapper implements XContentMapper, ArrayValueMapperPars
|
||||||
builder.field("type", CONTENT_TYPE);
|
builder.field("type", CONTENT_TYPE);
|
||||||
builder.field("path", pathType.name().toLowerCase());
|
builder.field("path", pathType.name().toLowerCase());
|
||||||
builder.field("lat_lon", enableLatLon);
|
builder.field("lat_lon", enableLatLon);
|
||||||
if (latMapper != null) {
|
builder.field("geohash", enableGeoHash);
|
||||||
builder.field("store", latMapper.store().name().toLowerCase());
|
builder.field("store", geoStringMapper.store().name().toLowerCase());
|
||||||
} else if (geohashMapper != null) {
|
builder.field("geohash_precision", precision);
|
||||||
builder.field("store", geohashMapper.store().name().toLowerCase());
|
|
||||||
}
|
|
||||||
builder.field("precision", precision);
|
|
||||||
if (precisionStep != null) {
|
if (precisionStep != null) {
|
||||||
builder.field("precision_step", precisionStep);
|
builder.field("precision_step", precisionStep);
|
||||||
}
|
}
|
||||||
|
@ -339,7 +366,7 @@ public class GeoPointFieldMapper implements XContentMapper, ArrayValueMapperPars
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class GeoHashFieldMapper extends StringFieldMapper {
|
public static class GeoStringFieldMapper extends StringFieldMapper {
|
||||||
|
|
||||||
public static class Builder extends AbstractFieldMapper.OpenBuilder<Builder, StringFieldMapper> {
|
public static class Builder extends AbstractFieldMapper.OpenBuilder<Builder, StringFieldMapper> {
|
||||||
|
|
||||||
|
@ -360,8 +387,8 @@ public class GeoPointFieldMapper implements XContentMapper, ArrayValueMapperPars
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public GeoHashFieldMapper build(BuilderContext context) {
|
@Override public GeoStringFieldMapper build(BuilderContext context) {
|
||||||
GeoHashFieldMapper fieldMapper = new GeoHashFieldMapper(buildNames(context),
|
GeoStringFieldMapper fieldMapper = new GeoStringFieldMapper(buildNames(context),
|
||||||
index, store, termVector, boost, omitNorms, omitTermFreqAndPositions, nullValue,
|
index, store, termVector, boost, omitNorms, omitTermFreqAndPositions, nullValue,
|
||||||
indexAnalyzer, searchAnalyzer);
|
indexAnalyzer, searchAnalyzer);
|
||||||
fieldMapper.includeInAll(includeInAll);
|
fieldMapper.includeInAll(includeInAll);
|
||||||
|
@ -369,7 +396,7 @@ public class GeoPointFieldMapper implements XContentMapper, ArrayValueMapperPars
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public GeoHashFieldMapper(Names names, Field.Index index, Field.Store store, Field.TermVector termVector, float boost, boolean omitNorms, boolean omitTermFreqAndPositions, String nullValue, NamedAnalyzer indexAnalyzer, NamedAnalyzer searchAnalyzer) {
|
public GeoStringFieldMapper(Names names, Field.Index index, Field.Store store, Field.TermVector termVector, float boost, boolean omitNorms, boolean omitTermFreqAndPositions, String nullValue, NamedAnalyzer indexAnalyzer, NamedAnalyzer searchAnalyzer) {
|
||||||
super(names, index, store, termVector, boost, omitNorms, omitTermFreqAndPositions, nullValue, indexAnalyzer, searchAnalyzer);
|
super(names, index, store, termVector, boost, omitNorms, omitTermFreqAndPositions, nullValue, indexAnalyzer, searchAnalyzer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ public class GeohashMappingGeoPointTests {
|
||||||
|
|
||||||
MatcherAssert.assertThat(doc.doc().getField("point.lat"), nullValue());
|
MatcherAssert.assertThat(doc.doc().getField("point.lat"), nullValue());
|
||||||
MatcherAssert.assertThat(doc.doc().getField("point.lon"), nullValue());
|
MatcherAssert.assertThat(doc.doc().getField("point.lon"), nullValue());
|
||||||
MatcherAssert.assertThat(doc.doc().get("point"), equalTo(GeoHashUtils.encode(1.2, 1.3)));
|
MatcherAssert.assertThat(doc.doc().get("point"), equalTo("1.2,1.3"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void testLatLonInOneValue() throws Exception {
|
@Test public void testLatLonInOneValue() throws Exception {
|
||||||
|
@ -67,7 +67,7 @@ public class GeohashMappingGeoPointTests {
|
||||||
|
|
||||||
MatcherAssert.assertThat(doc.doc().getField("point.lat"), nullValue());
|
MatcherAssert.assertThat(doc.doc().getField("point.lat"), nullValue());
|
||||||
MatcherAssert.assertThat(doc.doc().getField("point.lon"), nullValue());
|
MatcherAssert.assertThat(doc.doc().getField("point.lon"), nullValue());
|
||||||
MatcherAssert.assertThat(doc.doc().get("point"), equalTo(GeoHashUtils.encode(1.2, 1.3)));
|
MatcherAssert.assertThat(doc.doc().get("point"), equalTo("1.2,1.3"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void testGeoHashValue() throws Exception {
|
@Test public void testGeoHashValue() throws Exception {
|
||||||
|
@ -85,6 +85,7 @@ public class GeohashMappingGeoPointTests {
|
||||||
|
|
||||||
MatcherAssert.assertThat(doc.doc().getField("point.lat"), nullValue());
|
MatcherAssert.assertThat(doc.doc().getField("point.lat"), nullValue());
|
||||||
MatcherAssert.assertThat(doc.doc().getField("point.lon"), nullValue());
|
MatcherAssert.assertThat(doc.doc().getField("point.lon"), nullValue());
|
||||||
MatcherAssert.assertThat(doc.doc().get("point"), equalTo(GeoHashUtils.encode(1.2, 1.3)));
|
MatcherAssert.assertThat(doc.doc().get("point.geohash"), equalTo(GeoHashUtils.encode(1.2, 1.3)));
|
||||||
|
MatcherAssert.assertThat(doc.doc().get("point"), notNullValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,90 @@
|
||||||
|
/*
|
||||||
|
* Licensed to Elastic Search and Shay Banon under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. Elastic Search licenses this
|
||||||
|
* file to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.elasticsearch.index.mapper.xcontent.geopoint;
|
||||||
|
|
||||||
|
import org.elasticsearch.common.lucene.geo.GeoHashUtils;
|
||||||
|
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||||
|
import org.elasticsearch.index.mapper.ParsedDocument;
|
||||||
|
import org.elasticsearch.index.mapper.xcontent.MapperTests;
|
||||||
|
import org.elasticsearch.index.mapper.xcontent.XContentDocumentMapper;
|
||||||
|
import org.hamcrest.MatcherAssert;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import static org.hamcrest.Matchers.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author kimchy (shay.banon)
|
||||||
|
*/
|
||||||
|
public class LatLonAndGeohashMappingGeoPointTests {
|
||||||
|
|
||||||
|
@Test public void testLatLonValues() throws Exception {
|
||||||
|
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
|
||||||
|
.startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", true).field("geohash", true).endObject().endObject()
|
||||||
|
.endObject().endObject().string();
|
||||||
|
|
||||||
|
XContentDocumentMapper defaultMapper = MapperTests.newParser().parse(mapping);
|
||||||
|
|
||||||
|
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
|
||||||
|
.startObject()
|
||||||
|
.startObject("point").field("lat", 1.2).field("lon", 1.3).endObject()
|
||||||
|
.endObject()
|
||||||
|
.copiedBytes());
|
||||||
|
|
||||||
|
MatcherAssert.assertThat(doc.doc().getField("point.lat"), notNullValue());
|
||||||
|
MatcherAssert.assertThat(doc.doc().getField("point.lon"), notNullValue());
|
||||||
|
MatcherAssert.assertThat(doc.doc().get("point.geohash"), equalTo(GeoHashUtils.encode(1.2, 1.3)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test public void testLatLonInOneValue() throws Exception {
|
||||||
|
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
|
||||||
|
.startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", true).field("geohash", true).endObject().endObject()
|
||||||
|
.endObject().endObject().string();
|
||||||
|
|
||||||
|
XContentDocumentMapper defaultMapper = MapperTests.newParser().parse(mapping);
|
||||||
|
|
||||||
|
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
|
||||||
|
.startObject()
|
||||||
|
.field("point", "1.2,1.3")
|
||||||
|
.endObject()
|
||||||
|
.copiedBytes());
|
||||||
|
|
||||||
|
MatcherAssert.assertThat(doc.doc().getField("point.lat"), notNullValue());
|
||||||
|
MatcherAssert.assertThat(doc.doc().getField("point.lon"), notNullValue());
|
||||||
|
MatcherAssert.assertThat(doc.doc().get("point.geohash"), equalTo(GeoHashUtils.encode(1.2, 1.3)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test public void testGeoHashValue() throws Exception {
|
||||||
|
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
|
||||||
|
.startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", true).field("geohash", true).endObject().endObject()
|
||||||
|
.endObject().endObject().string();
|
||||||
|
|
||||||
|
XContentDocumentMapper defaultMapper = MapperTests.newParser().parse(mapping);
|
||||||
|
|
||||||
|
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
|
||||||
|
.startObject()
|
||||||
|
.field("point", GeoHashUtils.encode(1.2, 1.3))
|
||||||
|
.endObject()
|
||||||
|
.copiedBytes());
|
||||||
|
|
||||||
|
MatcherAssert.assertThat(doc.doc().getField("point.lat"), notNullValue());
|
||||||
|
MatcherAssert.assertThat(doc.doc().getField("point.lon"), notNullValue());
|
||||||
|
MatcherAssert.assertThat(doc.doc().get("point.geohash"), equalTo(GeoHashUtils.encode(1.2, 1.3)));
|
||||||
|
}
|
||||||
|
}
|
|
@ -52,7 +52,8 @@ public class LatLonMappingGeoPointTests {
|
||||||
assertThat(doc.doc().getField("point.lat").getBinaryValue(), nullValue());
|
assertThat(doc.doc().getField("point.lat").getBinaryValue(), nullValue());
|
||||||
assertThat(doc.doc().getField("point.lon"), notNullValue());
|
assertThat(doc.doc().getField("point.lon"), notNullValue());
|
||||||
assertThat(doc.doc().getField("point.lon").getBinaryValue(), nullValue());
|
assertThat(doc.doc().getField("point.lon").getBinaryValue(), nullValue());
|
||||||
assertThat(doc.doc().get("point"), equalTo(GeoHashUtils.encode(1.2, 1.3)));
|
assertThat(doc.doc().getField("point.geohash"), nullValue());
|
||||||
|
assertThat(doc.doc().get("point"), equalTo("1.2,1.3"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void testLatLonValuesStored() throws Exception {
|
@Test public void testLatLonValuesStored() throws Exception {
|
||||||
|
@ -72,7 +73,8 @@ public class LatLonMappingGeoPointTests {
|
||||||
assertThat(doc.doc().getField("point.lat").getBinaryValue(), equalTo(Numbers.doubleToBytes(1.2)));
|
assertThat(doc.doc().getField("point.lat").getBinaryValue(), equalTo(Numbers.doubleToBytes(1.2)));
|
||||||
assertThat(doc.doc().getField("point.lon"), notNullValue());
|
assertThat(doc.doc().getField("point.lon"), notNullValue());
|
||||||
assertThat(doc.doc().getField("point.lon").getBinaryValue(), equalTo(Numbers.doubleToBytes(1.3)));
|
assertThat(doc.doc().getField("point.lon").getBinaryValue(), equalTo(Numbers.doubleToBytes(1.3)));
|
||||||
assertThat(doc.doc().get("point"), equalTo(GeoHashUtils.encode(1.2, 1.3)));
|
assertThat(doc.doc().getField("point.geohash"), nullValue());
|
||||||
|
assertThat(doc.doc().get("point"), equalTo("1.2,1.3"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void testArrayLatLonValues() throws Exception {
|
@Test public void testArrayLatLonValues() throws Exception {
|
||||||
|
@ -95,10 +97,10 @@ public class LatLonMappingGeoPointTests {
|
||||||
assertThat(doc.doc().getFields("point.lon").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.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.lon")[0].getBinaryValue(), equalTo(Numbers.doubleToBytes(1.3)));
|
||||||
assertThat(doc.doc().getFields("point")[0].stringValue(), equalTo(GeoHashUtils.encode(1.2, 1.3)));
|
assertThat(doc.doc().getFields("point")[0].stringValue(), equalTo("1.2,1.3"));
|
||||||
assertThat(doc.doc().getFields("point.lat")[1].getBinaryValue(), equalTo(Numbers.doubleToBytes(1.4)));
|
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().getFields("point.lon")[1].getBinaryValue(), equalTo(Numbers.doubleToBytes(1.5)));
|
||||||
assertThat(doc.doc().getFields("point")[1].stringValue(), equalTo(GeoHashUtils.encode(1.4, 1.5)));
|
assertThat(doc.doc().getFields("point")[1].stringValue(), equalTo("1.4,1.5"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void testLatLonInOneValue() throws Exception {
|
@Test public void testLatLonInOneValue() throws Exception {
|
||||||
|
@ -116,7 +118,7 @@ public class LatLonMappingGeoPointTests {
|
||||||
|
|
||||||
assertThat(doc.doc().getField("point.lat"), notNullValue());
|
assertThat(doc.doc().getField("point.lat"), notNullValue());
|
||||||
assertThat(doc.doc().getField("point.lon"), notNullValue());
|
assertThat(doc.doc().getField("point.lon"), notNullValue());
|
||||||
assertThat(doc.doc().get("point"), equalTo(GeoHashUtils.encode(1.2, 1.3)));
|
assertThat(doc.doc().get("point"), equalTo("1.2,1.3"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void testLatLonInOneValueStored() throws Exception {
|
@Test public void testLatLonInOneValueStored() throws Exception {
|
||||||
|
@ -136,7 +138,7 @@ public class LatLonMappingGeoPointTests {
|
||||||
assertThat(doc.doc().getField("point.lat").getBinaryValue(), equalTo(Numbers.doubleToBytes(1.2)));
|
assertThat(doc.doc().getField("point.lat").getBinaryValue(), equalTo(Numbers.doubleToBytes(1.2)));
|
||||||
assertThat(doc.doc().getField("point.lon"), notNullValue());
|
assertThat(doc.doc().getField("point.lon"), notNullValue());
|
||||||
assertThat(doc.doc().getField("point.lon").getBinaryValue(), equalTo(Numbers.doubleToBytes(1.3)));
|
assertThat(doc.doc().getField("point.lon").getBinaryValue(), equalTo(Numbers.doubleToBytes(1.3)));
|
||||||
assertThat(doc.doc().get("point"), equalTo(GeoHashUtils.encode(1.2, 1.3)));
|
assertThat(doc.doc().get("point"), equalTo("1.2,1.3"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void testLatLonInOneValueArray() throws Exception {
|
@Test public void testLatLonInOneValueArray() throws Exception {
|
||||||
|
@ -159,10 +161,10 @@ public class LatLonMappingGeoPointTests {
|
||||||
assertThat(doc.doc().getFields("point.lon").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.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.lon")[0].getBinaryValue(), equalTo(Numbers.doubleToBytes(1.3)));
|
||||||
assertThat(doc.doc().getFields("point")[0].stringValue(), equalTo(GeoHashUtils.encode(1.2, 1.3)));
|
assertThat(doc.doc().getFields("point")[0].stringValue(), equalTo("1.2,1.3"));
|
||||||
assertThat(doc.doc().getFields("point.lat")[1].getBinaryValue(), equalTo(Numbers.doubleToBytes(1.4)));
|
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().getFields("point.lon")[1].getBinaryValue(), equalTo(Numbers.doubleToBytes(1.5)));
|
||||||
assertThat(doc.doc().getFields("point")[1].stringValue(), equalTo(GeoHashUtils.encode(1.4, 1.5)));
|
assertThat(doc.doc().getFields("point")[1].stringValue(), equalTo("1.4,1.5"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void testGeoHashValue() throws Exception {
|
@Test public void testGeoHashValue() throws Exception {
|
||||||
|
@ -180,7 +182,7 @@ public class LatLonMappingGeoPointTests {
|
||||||
|
|
||||||
assertThat(doc.doc().getField("point.lat"), notNullValue());
|
assertThat(doc.doc().getField("point.lat"), notNullValue());
|
||||||
assertThat(doc.doc().getField("point.lon"), notNullValue());
|
assertThat(doc.doc().getField("point.lon"), notNullValue());
|
||||||
assertThat(doc.doc().get("point"), equalTo(GeoHashUtils.encode(1.2, 1.3)));
|
assertThat(doc.doc().get("point"), notNullValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void testLatLonArray() throws Exception {
|
@Test public void testLatLonArray() throws Exception {
|
||||||
|
@ -200,7 +202,7 @@ public class LatLonMappingGeoPointTests {
|
||||||
assertThat(doc.doc().getField("point.lat").getBinaryValue(), nullValue());
|
assertThat(doc.doc().getField("point.lat").getBinaryValue(), nullValue());
|
||||||
assertThat(doc.doc().getField("point.lon"), notNullValue());
|
assertThat(doc.doc().getField("point.lon"), notNullValue());
|
||||||
assertThat(doc.doc().getField("point.lon").getBinaryValue(), nullValue());
|
assertThat(doc.doc().getField("point.lon").getBinaryValue(), nullValue());
|
||||||
assertThat(doc.doc().get("point"), equalTo(GeoHashUtils.encode(1.2, 1.3)));
|
assertThat(doc.doc().get("point"), equalTo("1.2,1.3"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void testLatLonArrayStored() throws Exception {
|
@Test public void testLatLonArrayStored() throws Exception {
|
||||||
|
@ -220,7 +222,7 @@ public class LatLonMappingGeoPointTests {
|
||||||
assertThat(doc.doc().getField("point.lat").getBinaryValue(), equalTo(Numbers.doubleToBytes(1.2)));
|
assertThat(doc.doc().getField("point.lat").getBinaryValue(), equalTo(Numbers.doubleToBytes(1.2)));
|
||||||
assertThat(doc.doc().getField("point.lon"), notNullValue());
|
assertThat(doc.doc().getField("point.lon"), notNullValue());
|
||||||
assertThat(doc.doc().getField("point.lon").getBinaryValue(), equalTo(Numbers.doubleToBytes(1.3)));
|
assertThat(doc.doc().getField("point.lon").getBinaryValue(), equalTo(Numbers.doubleToBytes(1.3)));
|
||||||
assertThat(doc.doc().get("point"), equalTo(GeoHashUtils.encode(1.2, 1.3)));
|
assertThat(doc.doc().get("point"), equalTo("1.2,1.3"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void testLatLonArrayArrayStored() throws Exception {
|
@Test public void testLatLonArrayArrayStored() throws Exception {
|
||||||
|
@ -243,9 +245,9 @@ public class LatLonMappingGeoPointTests {
|
||||||
assertThat(doc.doc().getFields("point.lon").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.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.lon")[0].getBinaryValue(), equalTo(Numbers.doubleToBytes(1.3)));
|
||||||
assertThat(doc.doc().getFields("point")[0].stringValue(), equalTo(GeoHashUtils.encode(1.2, 1.3)));
|
assertThat(doc.doc().getFields("point")[0].stringValue(), equalTo("1.2,1.3"));
|
||||||
assertThat(doc.doc().getFields("point.lat")[1].getBinaryValue(), equalTo(Numbers.doubleToBytes(1.4)));
|
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().getFields("point.lon")[1].getBinaryValue(), equalTo(Numbers.doubleToBytes(1.5)));
|
||||||
assertThat(doc.doc().getFields("point")[1].stringValue(), equalTo(GeoHashUtils.encode(1.4, 1.5)));
|
assertThat(doc.doc().getFields("point")[1].stringValue(), equalTo("1.4,1.5"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue