地理查詢編輯
Elasticsearch支持兩種類型的地理數據: geo_point
緯度/經度對字段的支持,和 geo_shape
領域,支持點、線、圓、多邊形、多等。
這組查詢:
-
geo_shape
查詢 - 發現文檔與幾何圖型相交,包含,或與指定的geo-shape不相交。
-
geo_bounding_box
查詢 - 發現文檔與geo-points落入指定的矩形。
-
geo_distance
查詢 - 發現文檔geo-points內指定的中心點的距離。
-
geo_distance_range
查詢 -
就像
geo_point
查詢,但是范圍是從一個指定的中心點的距離。 -
geo_polygon
查詢 - 發現文檔geo-points內指定的多邊形。
-
geohash_cell
查詢 - 找到的geo-points geohash相交的geohash指定點。
GeoShape查詢編輯
看到Geo形狀查詢
注意: geo_shape
類型使用 Spatial4J
和 JTS
,這兩個都是可選的依賴性。因此您必須添加 Spatial4J
和JTS
到類路徑中為了使用這種類型:
- <dependency>
- <groupId>com.spatial4j</groupId>
- <artifactId>spatial4j</artifactId>
- <version>0.4.1</version> <!--1-->
- </dependency>
- <dependency>
- <groupId>com.vividsolutions</groupId>
- <artifactId>jts</artifactId>
- <version>1.13</version> <!--2-->
- <exclusions>
- <exclusion>
- <groupId>xerces</groupId>
- <artifactId>xercesImpl</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
檢查更新Maven中央 |
|
檢查更新Maven中央 |
- // Import ShapeRelation and ShapeBuilder
- import org.elasticsearch.common.geo.ShapeRelation;
- import org.elasticsearch.common.geo.builders.ShapeBuilder;
- QueryBuilder qb = geoShapeQuery(
- "pin.location", //1
- ShapeBuilder.newMultiPoint() //2
- .point(0, 0)
- .point(0, 10)
- .point(10, 10)
- .point(10, 0)
- .point(0, 0),
- ShapeRelation.WITHIN); //3
場 |
|
形狀 |
|
關系可以 |
- // Using pre-indexed shapes
- QueryBuilder qb = geoShapeQuery(
- "pin.location", //1
- "DEU", //2
- "countries", //3
- ShapeRelation.WITHIN) //4
- .indexedShapeIndex("shapes") //5
- .indexedShapePath("location"); //6
場 |
|
文檔的ID包含預先索引的形狀。 |
|
索引類型預先索引形狀在哪里。 |
|
關系 |
|
預先索引的索引的名稱,形狀。默認為 形狀. |
|
包含預先索引的字段指定為路徑的形狀。默認為 形狀. |
地理邊界框查詢編輯
看到地理邊界框查詢
- QueryBuilder qb = geoBoundingBoxQuery("pin.location") //1
- .topLeft(40.73, -74.1) //2
- .bottomRight(40.717, -73.99); //3
- QueryBuilder qb = geoDistanceQuery("pin.location") //1
- .point(40, -70) //2
- .distance(200, DistanceUnit.KILOMETERS) //3
- .optimizeBbox("memory") //4
- .geoDistance(GeoDistance.ARC); //5
- QueryBuilder qb = geoDistanceRangeQuery("pin.location") //1
- .point(40, -70) //2
- .from("200km") //3
- .to("400km") //4
- .includeLower(true) //5
- .includeUpper(false) //6
- .optimizeBbox("memory") //7
- .geoDistance(GeoDistance.ARC); //8
- QueryBuilder qb = geoPolygonQuery("pin.location") //1
- .addPoint(40, -70) //2
- .addPoint(30, -80) //3
- .addPoint(20, -90); //4
Geohash細胞查詢編輯
- QueryBuilder qb = geoHashCellQuery("pin.location", //1
- new GeoPoint(13.4080, 52.5186)) //2
- .neighbors(true) //3
- .precision(3); //4
場 |
|
點。也可以是一個散列 |
|
的 |
|
精度水平
|