我正在执行此查询,在kibana中使用它具有预期的结果。
GET my_index/_search
{
"query": {
"bool" : {
"must" : {
"match_all" : {}
},
"filter" : {
"geo_shape" : {
"SitePoint" : {
"shape": {
"type": "polygon",
"coordinates" : [
[[18.85491,-33.92305],
[18.8604,-33.9319],
[18.85618,-33.9399],
[18.84809,-33.94153],
[18.85491,-33.92305]]
]
},
"relation": "within"
}
}
}
}
}
}
并且我正在尝试使用带有Kotlin或Java的ElasticsearchRepository构建可靠的东西,我真的在Internet上找不到很多,或者我不应该理解文档。
val coor = mutableListOf(org.locationtech.jts.geom.Coordinate(18.85491,-33.92305),
org.locationtech.jts.geom.Coordinate(18.8604,-33.9319),
org.locationtech.jts.geom.Coordinate(18.85618,-33.9399),
org.locationtech.jts.geom.Coordinate(18.84809,-33.94153),
org.locationtech.jts.geom.Coordinate(18.85491,-33.92305))
val query = QueryBuilders
.geoShapeQuery("objects", ShapeBuilders.newPolygon(coor))
.relation(ShapeRelation.WITHIN)
仅运行此命令即可查看查询,我有一个java.lang.ClassNotFoundException: org.locationtech.spatial4j.exception.InvalidShapeException
有人可以帮我吗?
经过一些研究后,我可以使用Spring的JPA进行查询
val filter = QueryBuilders.geoShapeQuery("SitePoint", ShapeBuilders.newPolygon(coordinates)).relation(ShapeRelation.WITHIN)
val searchQuery = NativeSearchQueryBuilder()
.withQuery(matchQuery("id", id))
.withFilter(filter)
.build()
return template.queryForList(searchQuery, MyClass::class.java)