Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Geo: Filter by distance based on location #279

Closed
kimchy opened this issue Jul 28, 2010 · 4 comments
Closed

Geo: Filter by distance based on location #279

kimchy opened this issue Jul 28, 2010 · 4 comments

Comments

@kimchy
Copy link
Member

kimchy commented Jul 28, 2010

The ability to define a query DSL filter, allowing to include only hits that exists within a specific distance from a geo point. Assuming the following indexed json:

{
    "pin" : {
        "location" : {
            "lat" : 40.12,
            "lon" : -71.34
        }
    }
}

Then the following simple query can be executed with a geo_distance filter:

{
    "filtered" : {
        "query" : {
            "match_all" : {}
        },
        "filter" : {
            "geo_distance" : {
                "distance" : "12km"
                "pin.location" : {
                    "lat" : 40,
                    "lon" : -70
                }
            }
        }
    }
}

Accepted Formats

In much the same way the geo_point type can accept different representation of the geo point, the filter can accept it as well:

Lat Lon As Properties

{
    "filtered" : {
        "query" : {
            "match_all" : {}
        },
        "filter" : {
            "geo_distance" : {
                "distance" : "12km"
                "pin.location" : {
                    "lat" : 40,
                    "lon" : -70
                }
            }
        }
    }
}

Lat Lon As Array

{
    "filtered" : {
        "query" : {
            "match_all" : {}
        },
        "filter" : {
            "geo_distance" : {
                "distance" : "12km"
                "pin.location" : [40, -70]
            }
        }
    }
}

Lat Lon As String

{
    "filtered" : {
        "query" : {
            "match_all" : {}
        },
        "filter" : {
            "geo_distance" : {
                "distance" : "12km"
                "pin.location" : "40,-70"
            }
        }
    }
}

Geohash

{
    "filtered" : {
        "query" : {
            "match_all" : {}
        },
        "filter" : {
            "geo_distance" : {
                "distance" : "12km"
                "pin.location" : "drm3btev3e86"
            }
        }
    }
}

Options

The following are options allowed on the filter:

  • distance: The distance to include hits in the filter. The distance can be a numeric value, and then the distance_unit (either mi/miles or km can be set) controlling the unit. Or a single string with the unit as well.
  • distance_type: How to compute the distance. Can either be arc (better precision) or plane (faster). Defaults to arc.

geo_point Type

The filter does not require the geo_point type to be set. It assumes that the location object indexed includes a lat and lon numeric values. The geo_point type follows these rules and allows for more flexible indexing options / structure, but is not required.

Multi Location Per Document

The geo_distance filter can work with multiple locations / points per document. Once a single location / point matches the filter, the document will be included in the filter.

@kimchy
Copy link
Member Author

kimchy commented Jul 28, 2010

implemented.

@mikenereson
Copy link

In examples, missing , after "distance" : "12km"

@gauraangkhurana
Copy link

What goes before this json request ?

I tried this 'geo_distance' filter query about 20 times but it gives me this error.

My Code :

`curl` -XGET localhost:9200/resume/_search -d  ' { {
    "filtered" : {
        "query" : {
            "match_all" : {}
        },
        "filter" : {
            "geo_distance" : {
                "distance" : "12km"
                "pin.location" : {
                    "lat" : 40,
                    "lon" : -70
                }
            }
        }
    }
}

The error produced is

{"error":{"root_cause":[{"type":"parsing_exception","reason":"Unknown key for a START_OBJECT in [filtered].","line":1,"col":19}],"type":"parsing_exception","reason":"Unknown key for a START_OBJECT in [filtered].","line":1,"col":19},"status":400}

Kindly help me.

@dadoonet
Copy link
Member

dadoonet commented Dec 6, 2016

Ask questions on discuss.elastic.co

Filtered query has been removed in 5.0. See breaking changes in doc

ClaudioMFreitas pushed a commit to ClaudioMFreitas/elasticsearch-1 that referenced this issue Nov 12, 2019
williamrandolph pushed a commit to williamrandolph/elasticsearch that referenced this issue Jun 4, 2020
mindw pushed a commit to mindw/elasticsearch that referenced this issue Sep 5, 2022
…21.10.25 (pull request elastic#279)

Add option to stack_power.py to specify max number of student generators to power up

* Add option to stack_power.py to specify max number of student generators to power up


Approved-by: Can Yildiz
Approved-by: fabien
cbuescher pushed a commit to cbuescher/elasticsearch that referenced this issue Oct 2, 2023
Since elastic#264 night-rally requires runtime JDK to be specified as cmd
param.

Relates to elastic/night-rally#264
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants