[英]Java ElasticSearach Bool Geo Query
我正在嘗試從我的應用程序中使用java api發出ElasticSearch查詢,但由於某些原因,我一直收到以下錯誤:
java.lang.NoClassDefFoundError:org / apache / lucene / search / spans / SpanBoostQuery位於org.elasticsearch.index.query.QueryBuilders.boolQuery(QueryBuilders.java:301)
以下是pom.xml中當前存在的依賴項:
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
<version>5.4.2</version>
</dependency>
<dependency>
<groupId>org.locationtech.spatial4j</groupId>
<artifactId>spatial4j</artifactId>
<version>0.6</version>
</dependency>
<dependency>
<groupId>com.vividsolutions</groupId>
<artifactId>jts</artifactId>
<version>1.13</version>
<exclusions>
<exclusion>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
</exclusion>
</exclusions>
</dependency>
編碼:
double lon = -115.14029016987968;
double lat = 36.17206351151878;
QueryBuilder fullq = boolQuery()
.must(matchAllQuery())
.filter(geoShapeQuery(
"geometry",
ShapeBuilders.newCircleBuilder().center(lon, lat).radius(10, DistanceUnit.METERS)).relation(ShapeRelation.INTERSECTS));
TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));
SearchRequestBuilder finalQuery = client.prepareSearch("speedlimit").setTypes("speedlimit")
.setQuery(fullq);
SearchResponse searchResponse = finalQuery.execute().actionGet();
SearchHits searchHits = searchResponse.getHits();
if (searchHits.getTotalHits() > 0) {
String strSpeed = JsonPath.read(searchResponse.toString(), "$.hits.hits[0]._source.properties.TITLE");
int speed = Integer.parseInt(strSpeed.substring(0, 2));
}
else if (searchHits.getTotalHits() <= 0){
System.out.println("nothing");
}
這是我要運行的查詢,我已經關注了ES文檔,但無法繼續進行下去。 有沒有人試圖運行這樣的查詢,還是我走錯了路線? 我很想放棄Java API,然后返回從Java進行HTTP調用,但是我想我會嘗試使用他們的Java API。 任何提示表示贊賞,謝謝。
在我刪除了與“ org.apache.lucene”相關的較早的依賴項之后,為我解決了此錯誤,我們需要確保所有org.apache.lucene依賴項都是最新的,並且與包含SpanBoostQuery的版本保持一致:
我在下面評論了,它起作用了:
<!--<dependency>-->
<!--<groupId>org.apache.lucene</groupId>-->
<!--<artifactId>lucene-spellchecker</artifactId>-->
<!--<version>3.6.2</version>-->
<!--</dependency>-->
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.