Skip to content

Commit

Permalink
Using generic ESPersistService
Browse files Browse the repository at this point in the history
  • Loading branch information
Wvdbrande committed Apr 23, 2018
1 parent a409087 commit 8807d77
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ Base uri to access Jolokia endpoint: http://localhost:8090/admin/jolokia.<br>
* https://www.elastic.co/elasticon/conf/2018/sf/the-state-of-geo-in-elasticsearch
* https://www.elastic.co/elasticon/conf/2017/sf/what-is-evolving-in-elasticsearch
* https://www.latlong.net/Show-Latitude-Longitude.html
* https://www.google.com/fusiontables/DataSource?docid=12Yp5H2L-W0VrHC68V4wG7DFgariZ26f5bRXIo5NB
* https://www.google.com/fusiontables/DataSource?docid=12Yp5H2L-W0VrHC68V4wG7DFgariZ26f5bRXIo5NB
* http://www.headwallphotonics.com/polygon-tool
28 changes: 14 additions & 14 deletions src/main/java/be/ictdynamic/ES_GEO_POC/service/GEO_Service.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,61 +119,61 @@ private static <T> T getObjectFromES_Hit(SearchHit hit, String objectType) {

}

public Set<CommuneRequest.Commune> geoBoundingBoxQuery(double[] corners) throws IOException {
public Set<RetailLocationsRequest.Location> geoBoundingBoxQuery(double[] corners) throws IOException {
Date startDate = new Date();

Set<CommuneRequest.Commune> communes = new LinkedHashSet<>();
Set<RetailLocationsRequest.Location> locations = new LinkedHashSet<>();
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();

QueryBuilder query = QueryBuilders.matchAllQuery();

QueryBuilder geoDistanceQueryBuilder = QueryBuilders
.geoBoundingBoxQuery("myLocation")
QueryBuilder geoQueryBuilder = QueryBuilders
.geoBoundingBoxQuery("location")
.setCorners(corners[0], corners[1], corners[2], corners[3]);

QueryBuilder finalQuery = QueryBuilders.boolQuery().must(query).filter(geoDistanceQueryBuilder);
QueryBuilder finalQuery = QueryBuilders.boolQuery().must(query).filter(geoQueryBuilder);

sourceBuilder.query(finalQuery).size(SIZE_ES_QUERY);

SearchRequest searchRequest = new SearchRequest("commune").source(sourceBuilder);
SearchRequest searchRequest = new SearchRequest("retail_locations").source(sourceBuilder);

SearchResponse searchResponse = restClient.search(searchRequest);

SearchHits hits = searchResponse.getHits();

for (SearchHit hit : hits.getHits()) {
communes.add(GEO_Service.getObjectFromES_Hit(hit, "commune"));
locations.add(GEO_Service.getObjectFromES_Hit(hit, "retailer"));
}

return timedReturn(LOGGER, new Object() {}.getClass().getEnclosingMethod().getName(), startDate.getTime(), communes);
return timedReturn(LOGGER, new Object() {}.getClass().getEnclosingMethod().getName(), startDate.getTime(), locations);
}

public Set<CommuneRequest.Commune> geoPolygonQuery(List<GeoPoint> geoPoints) throws IOException {
public Set<RetailLocationsRequest.Location> geoPolygonQuery(List<GeoPoint> geoPoints) throws IOException {
Date startDate = new Date();

Set<CommuneRequest.Commune> communes = new LinkedHashSet<>();
Set<RetailLocationsRequest.Location> locations = new LinkedHashSet<>();
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();

QueryBuilder query = QueryBuilders.matchAllQuery();

QueryBuilder geoQueryBuilder = QueryBuilders
.geoPolygonQuery("myLocation", geoPoints);
.geoPolygonQuery("location", geoPoints);

QueryBuilder finalQuery = QueryBuilders.boolQuery().must(query).filter(geoQueryBuilder);

sourceBuilder.query(finalQuery).size(SIZE_ES_QUERY);

SearchRequest searchRequest = new SearchRequest("commune").source(sourceBuilder);
SearchRequest searchRequest = new SearchRequest("retail_locations").source(sourceBuilder);

SearchResponse searchResponse = restClient.search(searchRequest);

SearchHits hits = searchResponse.getHits();

for (SearchHit hit : hits.getHits()) {
communes.add(GEO_Service.getObjectFromES_Hit(hit, "commune"));
locations.add(GEO_Service.getObjectFromES_Hit(hit, "retailer"));
}

return timedReturn(LOGGER, new Object() {}.getClass().getEnclosingMethod().getName(), startDate.getTime(), communes);
return timedReturn(LOGGER, new Object() {}.getClass().getEnclosingMethod().getName(), startDate.getTime(), locations);
}

public Map<String, Long> geoAggregation(GeoAggregationRequest geoAggregationRequest) throws IOException {
Expand Down

0 comments on commit 8807d77

Please sign in to comment.