本文整理汇总了Java中org.elasticsearch.index.mapper.GeoShapeFieldMapper类的典型用法代码示例。如果您正苦于以下问题:Java GeoShapeFieldMapper类的具体用法?Java GeoShapeFieldMapper怎么用?Java GeoShapeFieldMapper使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GeoShapeFieldMapper类属于org.elasticsearch.index.mapper包,在下文中一共展示了GeoShapeFieldMapper类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseGeometries
import org.elasticsearch.index.mapper.GeoShapeFieldMapper; //导入依赖的package包/类
/**
* Parse the geometries array of a GeometryCollection
*
* @param parser Parser that will be read from
* @return Geometry[] geometries of the GeometryCollection
* @throws IOException Thrown if an error occurs while reading from the XContentParser
*/
protected static GeometryCollectionBuilder parseGeometries(XContentParser parser, GeoShapeFieldMapper mapper) throws
IOException {
if (parser.currentToken() != XContentParser.Token.START_ARRAY) {
throw new ElasticsearchParseException("geometries must be an array of geojson objects");
}
XContentParser.Token token = parser.nextToken();
GeometryCollectionBuilder geometryCollection = ShapeBuilders.newGeometryCollection();
while (token != XContentParser.Token.END_ARRAY) {
ShapeBuilder shapeBuilder = GeoShapeType.parse(parser);
geometryCollection.shape(shapeBuilder);
token = parser.nextToken();
}
return geometryCollection;
}
示例2: parse
import org.elasticsearch.index.mapper.GeoShapeFieldMapper; //导入依赖的package包/类
/**
* Parse the geometry specified by the source document and return a ShapeBuilder instance used to
* build the actual geometry
* @param parser - parse utility object including source document
* @param shapeMapper - field mapper needed for index specific parameters
* @return ShapeBuilder - a builder instance used to create the geometry
*/
public static ShapeBuilder parse(XContentParser parser, GeoShapeFieldMapper shapeMapper) throws IOException {
if (parser.currentToken() == XContentParser.Token.VALUE_NULL) {
return null;
} else if (parser.currentToken() != XContentParser.Token.START_OBJECT) {
throw new ElasticsearchParseException("shape must be an object consisting of type and coordinates");
}
GeoShapeType shapeType = null;
Distance radius = null;
CoordinateNode node = null;
GeometryCollectionBuilder geometryCollections = null;
Orientation requestedOrientation = (shapeMapper == null) ? Orientation.RIGHT : shapeMapper.fieldType().orientation();
boolean coerce = (shapeMapper == null) ? GeoShapeFieldMapper.Defaults.COERCE.value() : shapeMapper.coerce().value();
XContentParser.Token token;
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
if (token == XContentParser.Token.FIELD_NAME) {
String fieldName = parser.currentName();
if (FIELD_TYPE.equals(fieldName)) {
parser.nextToken();
shapeType = GeoShapeType.forName(parser.text());
} else if (FIELD_COORDINATES.equals(fieldName)) {
parser.nextToken();
node = parseCoordinates(parser);
} else if (FIELD_GEOMETRIES.equals(fieldName)) {
parser.nextToken();
geometryCollections = parseGeometries(parser, shapeMapper);
} else if (CircleBuilder.FIELD_RADIUS.equals(fieldName)) {
parser.nextToken();
radius = Distance.parseDistance(parser.text());
} else if (FIELD_ORIENTATION.equals(fieldName)) {
parser.nextToken();
requestedOrientation = Orientation.fromString(parser.text());
} else {
parser.nextToken();
parser.skipChildren();
}
}
}
if (shapeType == null) {
throw new ElasticsearchParseException("shape type not included");
} else if (node == null && GeoShapeType.GEOMETRYCOLLECTION != shapeType) {
throw new ElasticsearchParseException("coordinates not included");
} else if (geometryCollections == null && GeoShapeType.GEOMETRYCOLLECTION == shapeType) {
throw new ElasticsearchParseException("geometries not included");
} else if (radius != null && GeoShapeType.CIRCLE != shapeType) {
throw new ElasticsearchParseException("field [{}] is supported for [{}] only", CircleBuilder.FIELD_RADIUS,
CircleBuilder.TYPE);
}
switch (shapeType) {
case POINT: return parsePoint(node);
case MULTIPOINT: return parseMultiPoint(node);
case LINESTRING: return parseLineString(node);
case MULTILINESTRING: return parseMultiLine(node);
case POLYGON: return parsePolygon(node, requestedOrientation, coerce);
case MULTIPOLYGON: return parseMultiPolygon(node, requestedOrientation, coerce);
case CIRCLE: return parseCircle(node, radius);
case ENVELOPE: return parseEnvelope(node);
case GEOMETRYCOLLECTION: return geometryCollections;
default:
throw new ElasticsearchParseException("shape type [{}] not included", shapeType);
}
}
示例3: testOrientationPersistence
import org.elasticsearch.index.mapper.GeoShapeFieldMapper; //导入依赖的package包/类
/**
* Test that orientation parameter correctly persists across cluster restart
*/
public void testOrientationPersistence() throws Exception {
String idxName = "orientation";
String mapping = XContentFactory.jsonBuilder().startObject().startObject("shape")
.startObject("properties").startObject("location")
.field("type", "geo_shape")
.field("orientation", "left")
.endObject().endObject()
.endObject().endObject().string();
// create index
assertAcked(prepareCreate(idxName).addMapping("shape", mapping, XContentType.JSON));
mapping = XContentFactory.jsonBuilder().startObject().startObject("shape")
.startObject("properties").startObject("location")
.field("type", "geo_shape")
.field("orientation", "right")
.endObject().endObject()
.endObject().endObject().string();
assertAcked(prepareCreate(idxName+"2").addMapping("shape", mapping, XContentType.JSON));
ensureGreen(idxName, idxName+"2");
internalCluster().fullRestart();
ensureGreen(idxName, idxName+"2");
// left orientation test
IndicesService indicesService = internalCluster().getInstance(IndicesService.class, findNodeName(idxName));
IndexService indexService = indicesService.indexService(resolveIndex(idxName));
MappedFieldType fieldType = indexService.mapperService().fullName("location");
assertThat(fieldType, instanceOf(GeoShapeFieldMapper.GeoShapeFieldType.class));
GeoShapeFieldMapper.GeoShapeFieldType gsfm = (GeoShapeFieldMapper.GeoShapeFieldType)fieldType;
ShapeBuilder.Orientation orientation = gsfm.orientation();
assertThat(orientation, equalTo(ShapeBuilder.Orientation.CLOCKWISE));
assertThat(orientation, equalTo(ShapeBuilder.Orientation.LEFT));
assertThat(orientation, equalTo(ShapeBuilder.Orientation.CW));
// right orientation test
indicesService = internalCluster().getInstance(IndicesService.class, findNodeName(idxName+"2"));
indexService = indicesService.indexService(resolveIndex((idxName+"2")));
fieldType = indexService.mapperService().fullName("location");
assertThat(fieldType, instanceOf(GeoShapeFieldMapper.GeoShapeFieldType.class));
gsfm = (GeoShapeFieldMapper.GeoShapeFieldType)fieldType;
orientation = gsfm.orientation();
assertThat(orientation, equalTo(ShapeBuilder.Orientation.COUNTER_CLOCKWISE));
assertThat(orientation, equalTo(ShapeBuilder.Orientation.RIGHT));
assertThat(orientation, equalTo(ShapeBuilder.Orientation.CCW));
}
示例4: createDefaultFieldType
import org.elasticsearch.index.mapper.GeoShapeFieldMapper; //导入依赖的package包/类
@Override
protected MappedFieldType createDefaultFieldType() {
return new GeoShapeFieldMapper.GeoShapeFieldType();
}
示例5: GeoHeatmapAggregatorFactory
import org.elasticsearch.index.mapper.GeoShapeFieldMapper; //导入依赖的package包/类
/**
* Called by the {@link GeoHeatmapAggregationBuilder}
*
* @param name
* the name of this heatmap aggregator
* @param field
* the indexed field on which to create the heatmap; must be a
* geo_shape
* @param inputShape
* indexed shapes must intersect inputShape to be counted; if
* null the world rectangle is used
* @param maxCells
* the maximum number of cells (grid squares) that could possibly
* be returned from the heatmap
* @param distErr
* the maximum error distance allowable between the indexed shape and the cells
* @param distErrPct
* the maximum error ratio between the indexed shape and the heatmap shape
* @param gridLevel
* manually set the granularity of the grid
* @param context
* the context of this aggregation
* @param parent
* the parent aggregation
* @param subFactoriesBuilder
* (not used)
* @param metaData
* aggregation metadata
* @throws IOException
* if an error occurs creating the factory
*/
GeoHeatmapAggregatorFactory(String name, String field, Optional<Shape> inputShape, Optional<Integer> maxCells,
Optional<Double> distErr, Optional<Double> distErrPct, Optional<Integer> gridLevel,
SearchContext context, AggregatorFactory<?> parent,
AggregatorFactories.Builder subFactoriesBuilder, Map<String, Object> metaData) throws IOException {
super(name, context, parent, subFactoriesBuilder, metaData);
MappedFieldType fieldType = context.mapperService().fullName(field);
if (fieldType.typeName().equals(GeoShapeFieldMapper.CONTENT_TYPE)) {
GeoShapeFieldType geoFieldType = (GeoShapeFieldType) fieldType;
this.strategy = geoFieldType.resolveStrategy(SpatialStrategy.RECURSIVE);
} else {
throw new AggregationInitializationException(String.format(Locale.ROOT,
"Field [%s] is a %s instead of a %s type",
field, fieldType.typeName(), GeoShapeFieldMapper.CONTENT_TYPE));
}
this.inputShape = inputShape.orElse(strategy.getSpatialContext().getWorldBounds());
this.maxCells = maxCells.orElse(DEFAULT_MAX_CELLS);
this.gridLevel = gridLevel.orElse(resolveGridLevel(distErr, distErrPct));
}