java - How to pass polygon points in geo_polygon Query in Elasticsearch? -
polygon points
13.049901579550138,77.60384321849386 13.050271501523547,77.6000084075878 13.042883570605907,77.60009104570553 13.042505842873242,77.60865383263827 13.039972708604349,77.6169725155289 13.04006230763758,77.62306611131774 13.036301472612582,77.62675523932252 13.027836648748504,77.63111238425978 13.026664014408041,77.63260862851725 13.02476188706518,77.63997438672054 13.01580550477802,77.66057241738156 12.994606646225883,77.66614853601016 12.99922317402202,77.67626586171559 12.999248673711989,77.6806137299943 12.989982441225264,77.68721899668857 12.967414209806904,77.700928481046 12.965565353801034,77.70119657236678 12.956563533462424,77.70009555907806 12.948645461168596,77.69833987361152 12.943956894161838,77.69679408243776 12.939778114785996,77.69436134214627 12.931071740988296,77.68511223031385 12.921149580164533,77.66436305248996 12.917680671328007,77.66871057636764 12.920113294517337,77.66953194946153 12.920753105482662,77.66763705053846 12.921023128671994,77.66772822363235 12.920722219835467,77.66810534751005 12.929401859011703,77.68625616968615 12.938520885214002,77.69594365785375 12.94313170583816,77.69862791756223 12.948114538831405,77.7002707263885 12.956224866537577,77.70206904092193 12.965587846198966,77.70321422763321 12.968104390193098,77.702849318954 12.991083558774735,77.68889020331143 13.00125472628801,77.6816398700057 13.001220625977979,77.67582553828441 12.997411953774119,77.66747866398984 13.017252695221979,77.66225978261843 13.026658912934819,77.64062721327947 13.02849598559196,77.63351337148275 13.029140951251495,77.63269041574023 13.037485927387419,77.62839496067748 13.04207469236242,77.62389368868227 13.041977091395651,77.6172558844711 13.04449275712676,77.60899456736173 13.044798229394091,77.60206975429448 13.048066898476453,77.60203319241221 13.04791082044986,77.60365118150614
i pass polygon array elasticsearch.
in es have geo_polygon query. below have written partial method.
partial query
public vendorsearchresult searchvendors(string query, geopoint[] polygon, costtype... costtypes) { try { query = urldecoder.decode(query, "utf-8").replace(",", " "); } catch (exception e1) { query = ""; } boolquerybuilder bqbuilder = new boolquerybuilder(); bqbuilder.must(new typequerybuilder(vendor_indextype)); if (!stringutils.isempty(query)){ /* * add query string boolquery */ bqbuilder.must(querybuilders.multimatchquery(query, vendor_searched_fields).type(type.phrase_prefix)); } bqbuilder.must(querybuilders.geopolygonquery("address.geopoint") .addpoint().....); /*how pass points addpoint(,); ?*/ return null; }
can guide me on how add multiple points using loop/any-other
update
public vendorsearchresult searchvendors(string query, list<geopoint> polygon, costtype... costtypes) { try { query = urldecoder.decode(query, "utf-8").replace(",", " "); } catch (exception e1) { query = ""; } boolquerybuilder bqbuilder = new boolquerybuilder(); bqbuilder.must(new typequerybuilder(vendor_indextype)); if (!stringutils.isempty(query)){ /* * add query string boolquery */ bqbuilder.must(querybuilders.multimatchquery(query, vendor_searched_fields).type(type.phrase_prefix)); } /* * iterate on polygon add each point query */ geopolygonquerybuilder gpqb = querybuilders.geopolygonquery("address.geopoint"); (geopoint gp : polygon) { if(string.valueof(gp.getlat()).equals("nan")){ }else{ gpqb.addpoint(gp.getlat(), gp.getlon()); } } bqbuilder.must(gpqb); /* * add vendortype query, if provided */ if ( costtypes != null && costtypes.length > 0 ) { (costtype costtype : costtypes) { bqbuilder.should(querybuilders.termquery("vendortype", costtype.name().tolowercase())); } bqbuilder.minimumnumbershouldmatch(1); } vendorsearchresult sr = elasticsearch(bqbuilder, sortfield, sortorder.asc); return sr; }
for es 2.x, there's example available online at:
geopolygonquerybuilder gpqb = querybuilders.geopolygonquery("address.geopoint"); // iterate on polygon (geopoint gp : polygon) { gpqb.addpoint(gp.lat(), gp.lon()); }
as of es 5, you'll able as shown here:
import org.elasticsearch.index.search.geo.geopoint; list<geopoint> points = new arraylist<geopoint>(); // iterate on polygon (geopoint gp : polygon) { points.add(new geopoint(gp.lat(), gp.lon())); } querybuilder qb = querybuilders.geopolygonquery("address.geopoint", points);
Comments
Post a Comment