summaryrefslogtreecommitdiff
path: root/docs/reference/query-dsl/filters/geo-distance-filter.asciidoc
blob: f5013983066d95ea210d01a75513e2f056ec2a2d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
[[query-dsl-geo-distance-filter]]
=== Geo Distance Filter

Filters documents that include only hits that exists within a specific
distance from a geo point. Assuming the following indexed json:

[source,js]
--------------------------------------------------
{
    "pin" : {
        "location" : {
            "lat" : 40.12,
            "lon" : -71.34
        }
    }
}
--------------------------------------------------

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

[source,js]
--------------------------------------------------
{
    "filtered" : {
        "query" : {
            "match_all" : {}
        },
        "filter" : {
            "geo_distance" : {
                "distance" : "200km",
                "pin.location" : {
                    "lat" : 40,
                    "lon" : -70
                }
            }
        }
    }
}
--------------------------------------------------

[float]
==== 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:

[float]
===== Lat Lon As Properties

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

[float]
===== Lat Lon As Array

Format in `[lon, lat]`, note, the order of lon/lat here in order to
conform with http://geojson.org/[GeoJSON].

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

[float]
===== Lat Lon As String

Format in `lat,lon`.

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

[float]
===== Geohash

[source,js]
--------------------------------------------------
{
    "filtered" : {
        "query" : {
            "match_all" : {}
        },
        "filter" : {
            "geo_distance" : {
                "distance" : "12km",
                "pin.location" : "drm3btev3e86"
            }
        }
    }
}
--------------------------------------------------

[float]
==== Options

The following are options allowed on the filter:

[horizontal]

`distance`::

    The radius of the circle centred on the specified location. Points which
    fall into this circle are considered to be matches. The `distance` can be
    specified in various units. See <<distance-units>>.

`distance_type`::

    How to compute the distance. Can either be `arc` (better precision),
    `sloppy_arc` (faster but less precise) or `plane` (fastest). Defaults
    to `sloppy_arc`.

`optimize_bbox`::

    Whether to use the optimization of first running a bounding box check
    before the distance check. Defaults to `memory` which will do in memory
    checks. Can also have values of `indexed` to use indexed value check (make
    sure the `geo_point` type index lat lon in this case), or `none` which
    disables bounding box optimization.


[float]
==== geo_point Type

The filter *requires* the `geo_point` type to be set on the relevant
field.

[float]
==== 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.

[float]
==== Caching

The result of the filter is not cached by default. The `_cache` can be
set to `true` to cache the *result* of the filter. This is handy when
the same point and distance parameters are used on several (many) other
queries. Note, the process of caching the first execution is higher when
caching (since it needs to satisfy different queries).