How to get all documents with geo_point within 2-3 polygons(geo_shape) with single index?

Hi,

I have one index say "all_geo_docs" which contains all documents and all have a geo_shape field with type geo_shape and geo_point field with type geo_point.

Now I have one field named 'org_type' in all docs with value 'type_poly' or 'type_point'. If a value is 'type_poly' that means that doc is Polygon or else if the value is 'type_point' that means that doc is Point.

Now from the same index, I want to get all documents(with type geo_point) for which point of the doc is within 2-3 polygons(which exist in the same index with type geo_shape). I have name and id of that 2-3 polygons. How can I write geo_query for the same?

In short, I want to get all geo_point documents for which point lies within specific 2-3 polygons?

Thanks in advance.

I am trying to understand the question and I am not sure what you mean with 2-3 polygons. Could you elaborate a bit more what do you mean?

It is always a good practice to provide an example (mappings, data and queries) that shows the expected behaviour.

Hi,

Thanks for the reply.

So I have only one index with 2 fields with type geo_point and geo_shape. To be clear, geo_shapes are the polygon geo-json of the boundary on google map for region. So let's say I have 10 geo_shapes. So what I want in the result is find all geo_points which fall within 2-3 of the geo_shapes.

Solution or say patch I used for the same: I was trying to use the geo_shape query with geo_point data type so this is not possible as geo_share query won't work with geo_point. So what I did is I have indexed geo_point as a geo_shape type and it's working as expected.

It's working perfectly and I don't know if it's a proper way or patch only.

Thanks,
Mayur

You are right, you cannot use geo_shape query with a geo point field. You have to use GeoPolygon query but cannot be mixed up with geo_shape fields.

I think it is a proper solution in this case.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.