Search geo_point Location by latitude and longitude - Java Query

Trying a Java query to search Locations by latitude/longitude pair:
(Locations is indexed as geo_point, with lat_lon set to true)

SearchResponse response =
client.prepareSearch("index1").setTypes("pin").setQuery((filteredQuery(matchAllQuery(),
geoDistanceFilter("location").distance("1km").point(latitude,
longitude)))).execute().actionGet();

This query works Ok, however it requires specifying a "distance" in the
filter, Locations in my index should be unique,
and so I 'm looking into another option to construct a query given only
latitude & longitude as inputs, and the result being one or none.

I was wondering if specifying a distance may yields more than a single
point.

You mean you want to check for exact match?

On Thu, Jun 7, 2012 at 1:59 PM, Ahmed Yehia ahmed.yehia.m@gmail.com wrote:

Trying a Java query to search Locations by latitude/longitude pair:
(Locations is indexed as geo_point, with lat_lon set to true)

SearchResponse response =
client.prepareSearch("index1").setTypes("pin").setQuery((filteredQuery(matchAllQuery(),
geoDistanceFilter("location").distance("1km").point(latitude,
longitude)))).execute().actionGet();

This query works Ok, however it requires specifying a "distance" in the
filter, Locations in my index should be unique,
and so I 'm looking into another option to construct a query given only
latitude & longitude as inputs, and the result being one or none.

I was wondering if specifying a distance may yields more than a single
point.

Yes, this should be the case.
Though I 'd be Ok with specifying an arbitrary distance if it has no effect
in this context.

On Sunday, June 10, 2012, Shay Banon wrote:

You mean you want to check for exact match?

On Thu, Jun 7, 2012 at 1:59 PM, Ahmed Yehia <ahmed.yehia.m@gmail.com<javascript:_e({}, 'cvml', 'ahmed.yehia.m@gmail.com');>

wrote:

Trying a Java query to search Locations by latitude/longitude pair:
(Locations is indexed as geo_point, with lat_lon set to true)

SearchResponse response =
client.prepareSearch("index1").setTypes("pin").setQuery((filteredQuery(matchAllQuery(),
geoDistanceFilter("location").distance("1km").point(latitude,
longitude)))).execute().actionGet();

This query works Ok, however it requires specifying a "distance" in the
filter, Locations in my index should be unique,
and so I 'm looking into another option to construct a query given only
latitude & longitude as inputs, and the result being one or none.

I was wondering if specifying a distance may yields more than a single
point.

--

  • Ahmed

For exact match, you can have the lat and lon indexed (see the geo_type
mapping for it) and execute a query on both.

On Mon, Jun 11, 2012 at 12:12 AM, Ahmed Yehia ahmed.yehia.m@gmail.comwrote:

Yes, this should be the case.
Though I 'd be Ok with specifying an arbitrary distance if it has no
effect in this context.

On Sunday, June 10, 2012, Shay Banon wrote:

You mean you want to check for exact match?

On Thu, Jun 7, 2012 at 1:59 PM, Ahmed Yehia ahmed.yehia.m@gmail.comwrote:

Trying a Java query to search Locations by latitude/longitude pair:
(Locations is indexed as geo_point, with lat_lon set to true)

SearchResponse response =
client.prepareSearch("index1").setTypes("pin").setQuery((filteredQuery(matchAllQuery(),
geoDistanceFilter("location").distance("1km").point(latitude,
longitude)))).execute().actionGet();

This query works Ok, however it requires specifying a "distance" in the
filter, Locations in my index should be unique,
and so I 'm looking into another option to construct a query given only
latitude & longitude as inputs, and the result being one or none.

I was wondering if specifying a distance may yields more than a single
point.

--

  • Ahmed