]> git.openstreetmap.org Git - nominatim.git/blob - docs/api/Search.md
Merge remote-tracking branch 'upstream/master'
[nominatim.git] / docs / api / Search.md
1 # Search queries
2
3 The search API allows you to look up a location from a textual description
4 or address. Nominatim supports structured and free-form search queries.
5
6 The search query may also contain
7 [special phrases](https://wiki.openstreetmap.org/wiki/Nominatim/Special_Phrases)
8 which are translated into specific OpenStreetMap (OSM) tags (e.g. Pub => `amenity=pub`).
9 This can be used to narrow down the kind of objects to be returned.
10
11 !!! note
12     Special phrases are not suitable to query all objects of a certain type in an
13     area. Nominatim will always just return a collection of the best matches. To
14     download OSM data by object type, use the [Overpass API](https://overpass-api.de/).
15
16 ## Endpoint
17
18 The search API has the following format:
19
20 ```
21    https://nominatim.openstreetmap.org/search?<params>
22 ```
23
24 !!! danger "Deprecation warning"
25     The API can also be used with the URL
26     `https://nominatim.openstreetmap.org/search.php`. This is now deprecated
27     and will be removed in future versions.
28
29 The query term can be given in two different forms: free-form or structured.
30
31 ### Free-form query
32
33 | Parameter | Value |
34 |-----------| ----- |
35 | q         | Free-form query string to search for |
36
37 In this form, the query can be unstructured.
38 Free-form queries are processed first left-to-right and then right-to-left if that fails. So you may search for
39 [pilkington avenue, birmingham](https://nominatim.openstreetmap.org/search?q=pilkington+avenue,birmingham) as well as for
40 [birmingham, pilkington avenue](https://nominatim.openstreetmap.org/search?q=birmingham,+pilkington+avenue).
41 Commas are optional, but improve performance by reducing the complexity of the search.
42
43 The free-form may also contain special phrases to describe the type of
44 place to be returned or a coordinate to search close to a position.
45
46 ### Structured query
47
48 | Parameter  | Value |
49 |----------- | ----- |
50 | amenity    | name and/or type of POI |
51 | street     | housenumber and streetname |
52 | city       | city |
53 | county     | county |
54 | state      | state |
55 | country    | country |
56 | postalcode | postal code |
57
58 The structured form of the search query allows to lookup up an address
59 that is already split into its components. Each parameter represents a field
60 of the address. All parameters are optional. You should only use the ones
61 that are relevant for the address you want to geocode.
62
63 !!! Attention
64     Cannot be combined with the `q=<query>` parameter. Newer versions of
65     the API will return an error if you do so. Older versions simply return
66     unexpected results.
67
68 ## Parameters
69
70 The following parameters can be used to further restrict the search and
71 change the output. They are usable for both forms of the search query.
72
73 ### Output format
74
75 | Parameter | Value | Default |
76 |-----------| ----- | ------- |
77 | format    | one of: `xml`, `json`, `jsonv2`, `geojson`, `geocodejson` | `jsonv2` |
78
79 See [Place Output Formats](Output.md) for details on each format.
80
81 !!! note
82     The Nominatim service at
83     [https://nominatim.openstreetmap.org](https://nominatim.openstreetmap.org)
84     has a different default behaviour for historical reasons. When the
85     `format` parameter is omitted, the request will be forwarded to the Web UI.
86
87
88 | Parameter | Value | Default |
89 |-----------| ----- | ------- |
90 | json_callback | function name | _unset_ |
91
92 When given, then JSON output will be wrapped in a callback function with
93 the given name. See [JSONP](https://en.wikipedia.org/wiki/JSONP) for more
94 information.
95
96 Only has an effect for JSON output formats.
97
98 | Parameter | Value | Default |
99 |-----------| ----- | ------- |
100 | limit     | number | 10 |
101
102 Limit the maximum number of returned results. Cannot be more than 40.
103 Nominatim may decide to return less results than given, if additional
104 results do not sufficiently match the query.
105
106
107 ### Output details
108
109 | Parameter | Value | Default |
110 |-----------| ----- | ------- |
111 | addressdetails | 0 or 1 | 0 |
112
113 When set to 1, include a breakdown of the address into elements.
114 The exact content of the address breakdown depends on the output format.
115
116 !!! tip
117     If you are interested in a stable classification of address categories
118     (suburb, city, state, etc), have a look at the `geocodejson` format.
119     All other formats return classifications according to OSM tagging.
120     There is a much larger set of categories and they are not always consistent,
121     which makes them very hard to work with.
122
123
124 | Parameter | Value | Default |
125 |-----------| ----- | ------- |
126 | extratags | 0 or 1 | 0 |
127
128 When set to 1, the response include any additional information in the result
129 that is available in the database, e.g. wikipedia link, opening hours.
130
131
132 | Parameter | Value | Default |
133 |-----------| ----- | ------- |
134 | namedetails | 0 or 1 | 0 |
135
136 When set to 1, include a full list of names for the result. These may include
137 language variants, older names, references and brand.
138
139
140 ### Language of results
141
142 | Parameter | Value | Default |
143 |-----------| ----- | ------- |
144 | accept-language | browser language string | content of "Accept-Language" HTTP header |
145
146 Preferred language order for showing search results. This may either be
147 a simple comma-separated list of language codes or have the same format
148 as the ["Accept-Language" HTTP header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language).
149
150 !!! tip
151     First-time users of Nominatim tend to be confused that they get different
152     results when using Nominatim in the browser versus in a command-line tool
153     like wget or curl. The command-line tools
154     usually don't send any Accept-Language header, prompting Nominatim
155     to show results in the local language. Browsers on the contratry always
156     send the currently chosen browser language.
157
158 ### Result restriction
159
160 There are two ways to influence the results. *Filters* exclude certain
161 kinds of results completely. *Boost parameters* only change the order of the
162 results and thus give a preference to some results over others.
163
164 | Parameter | Value | Default |
165 |-----------| ----- | ------- |
166 | countrycodes | comma-separated list of country codes | _unset_ |
167
168 Filer that limits the search results to one or more countries.
169 The country code must be the
170 [ISO 3166-1alpha2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) code
171 of the country, e.g. `gb` for the United Kingdom, `de` for Germany.
172
173 Each place in Nominatim is assigned to one country code based
174 on OSM country boundaries. In rare cases a place may not be in any country
175 at all, for example, when it is in international waters. These places are
176 also excluded when the filter is set.
177
178 !!! Note
179     This parameter should not be confused with the 'country' parameter of
180     the structured query. The 'country' parameter contains a search term
181     and will be handled with some fuzziness. The `countrycodes` parameter
182     is a hard filter and as such should be prefered. Having both parameters
183     in the same query will work. If the parameters contradict each other,
184     the search will come up empty.
185
186 | Parameter | Value | Default |
187 |-----------| ----- | ------- |
188 | layer     | comma-separated list of: `address`, `poi`, `railway`, `natural`, `manmade` | _unset_ (no restriction) |
189
190 The layer filter allows to select places by themes.
191
192 The `address` layer contains all places that make up an address:
193 address points with house numbers, streets, inhabited places (suburbs, villages,
194 cities, states tec.) and administrative boundaries.
195
196 The `poi` layer selects all point of interest. This includes classic POIs like
197 restaurants, shops, hotels but also less obvious features like recycling bins,
198 guideposts or benches.
199
200 The `railway` layer includes railway infrastructure like tracks.
201 Note that in Nominatim's standard configuration, only very few railway
202 features are imported into the database.
203
204 The `natural` layer collects feautures like rivers, lakes and mountains while
205 the `manmade` layer functions as a catch-all for features not covered by the
206 other layers.
207
208 | Parameter | Value | Default |
209 |-----------| ----- | ------- |
210 | featureType | one of: `country`, `state`, `city`, `settlement` | _unset_ |
211
212 The featureType allows to have a more fine-grained selection for places
213 from the address layer. Results can be restricted to places that make up
214 the 'state', 'country' or 'city' part of an address. A featureType of
215 settlement selects any human inhabited feature from 'state' down to
216 'neighbourhood'.
217
218 When featureType ist set, then results are automatically restricted
219 to the address layer (see above).
220
221 !!! tip
222     Instead of using the featureType filters `country`, `state` or `city`,
223     you can also use a structured query without the finer-grained parameters
224     amenity or street.
225
226 | Parameter | Value | Default |
227 |-----------| ----- | ------- |
228 | exclude_place_ids | comma-separeted list of place ids |
229
230 If you do not want certain OSM objects to appear in the search
231 result, give a comma separated list of the `place_id`s you want to skip.
232 This can be used to retrieve additional search results. For example, if a
233 previous query only returned a few results, then including those here would
234 cause the search to return other, less accurate, matches (if possible).
235
236 | Parameter | Value | Default |
237 |-----------| ----- | ------- |
238 | viewbox   | `<x1>,<y1>,<x2>,<y2>` | _unset_ |
239
240 Boost parameter which focuses the search on the given area.
241 Any two corner points of the box are accepted as long as they make a proper
242 box. `x` is longitude, `y` is latitude.
243
244 | Parameter | Value  | Default |
245 |-----------| -----  | ------- |
246 | bounded   | 0 or 1 | 0       |
247
248 When set to 1, then it turns the 'viewbox' parameter (see above) into
249 a filter paramter, excluding any results outside the viewbox.
250
251 When `bounded=1` is given and the viewbox is small enough, then an amenity-only
252 search is allowed. Give the special keyword for the amenity in square
253 brackets, e.g. `[pub]` and a selection of objects of this type is returned.
254 There is no guarantee that the result returns all objects in the area.
255
256
257 ### Polygon output
258
259 | Parameter | Value  | Default |
260 |-----------| -----  | ------- |
261 | polygon_geojson | 0 or 1 | 0 |
262 | polygon_kml     | 0 or 1 | 0 |
263 | polygon_svg     | 0 or 1 | 0 |
264 | polygon_text    | 0 or 1 | 0 |
265
266 Add the full geometry of the place to the result output. Output formats
267 in GeoJSON, KML, SVG or WKT are supported. Only one of these
268 options can be used at a time.
269
270 | Parameter | Value  | Default |
271 |-----------| -----  | ------- |
272 | polygon_threshold | floating-point number | 0.0 |
273
274 When one of the polygon_* outputs is chosen, return a simplified version
275 of the output geometry. The parameter describes the
276 tolerance in degrees with which the geometry may differ from the original
277 geometry. Topology is preserved in the geometry.
278
279 ### Other
280
281 | Parameter | Value  | Default |
282 |-----------| -----  | ------- |
283 | email     | valid email address | _unset_ |
284
285 If you are making large numbers of request please include an appropriate email
286 address to identify your requests. See Nominatim's
287 [Usage Policy](https://operations.osmfoundation.org/policies/nominatim/) for more details.
288
289 | Parameter | Value  | Default |
290 |-----------| -----  | ------- |
291 | dedupe    | 0 or 1 | 1       |
292
293 Sometimes you have several objects in OSM identifying the same place or
294 object in reality. The simplest case is a street being split into many
295 different OSM ways due to different characteristics. Nominatim will
296 attempt to detect such duplicates and only return one match. Setting
297 this parameter to 0 disables this deduplication mechanism and
298 ensures that all results are returned.
299
300 | Parameter | Value  | Default |
301 |-----------| -----  | ------- |
302 | debug     | 0 or 1 | 0       |
303
304 Output assorted developer debug information. Data on internals of Nominatim's
305 "search loop" logic, and SQL queries. The output is HTML format.
306 This overrides the specified machine readable format.
307
308
309 ## Examples
310
311
312 ##### XML with KML polygon
313
314 * [https://nominatim.openstreetmap.org/search?q=135+pilkington+avenue,+birmingham&format=xml&polygon_kml=1&addressdetails=1](https://nominatim.openstreetmap.org/search?q=135+pilkington+avenue,+birmingham&format=xml&polygon_kml=1&addressdetails=1)
315
316 ```xml
317 <?xml version="1.0" encoding="UTF-8" ?>
318 <searchresults timestamp="Tue, 08 Aug 2023 15:45:41 +00:00"
319                attribution="Data © OpenStreetMap contributors, ODbL 1.0. http://osm.org/copyright"
320                querystring="135 pilkington avenue, birmingham"
321                more_url="https://nominatim.openstreetmap.org/search?q=135+pilkington+avenue%2C+birmingham&amp;polygon_kml=1&amp;addressdetails=1&amp;limit=20&amp;exclude_place_ids=125279639&amp;format=xml"
322                exclude_place_ids="125279639">
323   <place place_id="125279639"
324          osm_type="way"
325          osm_id="90394480"
326          lat="52.5487921"
327          lon="-1.8164308"
328          boundingbox="52.5487473,52.5488481,-1.8165130,-1.8163464"
329          place_rank="30"
330          address_rank="30"
331          display_name="135, Pilkington Avenue, Maney, Sutton Coldfield, Wylde Green, Birmingham, West Midlands Combined Authority, England, B72 1LH, United Kingdom"
332          class="building"
333          type="residential"
334          importance="9.999999994736442e-08">
335     <geokml>
336       <Polygon>
337         <outerBoundaryIs>
338           <LinearRing>
339             <coordinates>-1.816513,52.5487566 -1.816434,52.5487473 -1.816429,52.5487629 -1.8163717,52.5487561 -1.8163464,52.5488346 -1.8164599,52.5488481 -1.8164685,52.5488213 -1.8164913,52.548824 -1.816513,52.5487566</coordinates>
340           </LinearRing>
341         </outerBoundaryIs>
342       </Polygon>
343     </geokml>
344     <house_number>135</house_number>
345     <road>Pilkington Avenue</road>
346     <hamlet>Maney</hamlet>
347     <town>Sutton Coldfield</town>
348     <village>Wylde Green</village>
349     <city>Birmingham</city>
350     <ISO3166-2-lvl8>GB-BIR</ISO3166-2-lvl8>
351     <state_district>West Midlands Combined Authority</state_district>
352     <state>England</state>
353     <ISO3166-2-lvl4>GB-ENG</ISO3166-2-lvl4>
354     <postcode>B72 1LH</postcode>
355     <country>United Kingdom</country>
356     <country_code>gb</country_code>
357   </place>
358 </searchresults>
359 ```
360
361 ##### JSON with SVG polygon
362
363 [https://nominatim.openstreetmap.org/search?q=Unter%20den%20Linden%201%20Berlin&format=json&addressdetails=1&limit=1&polygon_svg=1](https://nominatim.openstreetmap.org/search?q=Unter%20den%20Linden%201%20Berlin&format=json&addressdetails=1&limit=1&polygon_svg=1)
364
365 ```json
366 [
367   {
368     "address": {
369       "ISO3166-2-lvl4": "DE-BE",
370       "borough": "Mitte",
371       "city": "Berlin",
372       "country": "Deutschland",
373       "country_code": "de",
374       "historic": "Kommandantenhaus",
375       "house_number": "1",
376       "neighbourhood": "Friedrichswerder",
377       "postcode": "10117",
378       "road": "Unter den Linden",
379       "suburb": "Mitte"
380     },
381     "boundingbox": [
382       "52.5170798",
383       "52.5173311",
384       "13.3975116",
385       "13.3981577"
386     ],
387     "class": "historic",
388     "display_name": "Kommandantenhaus, 1, Unter den Linden, Friedrichswerder, Mitte, Berlin, 10117, Deutschland",
389     "importance": 0.8135042058306902,
390     "lat": "52.51720765",
391     "licence": "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright",
392     "lon": "13.397834399325466",
393     "osm_id": 15976890,
394     "osm_type": "way",
395     "place_id": 108681845,
396     "svg": "M 13.3975116 -52.5172905 L 13.397549 -52.5170798 13.397715 -52.5170906 13.3977122 -52.5171064 13.3977392 -52.5171086 13.3977417 -52.5170924 13.3979655 -52.5171069 13.3979623 -52.5171233 13.3979893 -52.5171248 13.3979922 -52.5171093 13.3981577 -52.5171203 13.398121 -52.5173311 13.3978115 -52.5173103 Z",
397     "type": "house"
398   }
399 ]
400 ```
401
402 ##### JSON with address details
403
404 [https://nominatim.openstreetmap.org/search?addressdetails=1&q=bakery+in+berlin+wedding&format=jsonv2&limit=1](https://nominatim.openstreetmap.org/search?addressdetails=1&q=bakery+in+berlin+wedding&format=jsonv2&limit=1)
405
406 ```json
407 [
408   {
409     "address": {
410       "ISO3166-2-lvl4": "DE-BE",
411       "borough": "Mitte",
412       "city": "Berlin",
413       "country": "Deutschland",
414       "country_code": "de",
415       "neighbourhood": "Sprengelkiez",
416       "postcode": "13347",
417       "road": "Lindower Straße",
418       "shop": "Ditsch",
419       "suburb": "Wedding"
420     },
421     "addresstype": "shop",
422     "boundingbox": [
423       "52.5427201",
424       "52.5427654",
425       "13.3668619",
426       "13.3669442"
427     ],
428     "category": "shop",
429     "display_name": "Ditsch, Lindower Straße, Sprengelkiez, Wedding, Mitte, Berlin, 13347, Deutschland",
430     "importance": 9.99999999995449e-06,
431     "lat": "52.54274275",
432     "licence": "Data © OpenStreetMap contributors, ODbL 1.0. http://osm.org/copyright",
433     "lon": "13.36690305710228",
434     "name": "Ditsch",
435     "osm_id": 437595031,
436     "osm_type": "way",
437     "place_id": 204751033,
438     "place_rank": 30,
439     "type": "bakery"
440   }
441 ]
442 ```
443
444 ##### GeoJSON
445
446 [https://nominatim.openstreetmap.org/search?q=17+Strada+Pictor+Alexandru+Romano%2C+Bukarest&format=geojson](https://nominatim.openstreetmap.org/search?q=17+Strada+Pictor+Alexandru+Romano%2C+Bukarest&format=geojson)
447
448 ```json
449 {
450   "type": "FeatureCollection",
451   "licence": "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright",
452   "features": [
453     {
454       "type": "Feature",
455       "properties": {
456         "place_id": "35811445",
457         "osm_type": "node",
458         "osm_id": "2846295644",
459         "display_name": "17, Strada Pictor Alexandru Romano, Bukarest, Bucharest, Sector 2, Bucharest, 023964, Romania",
460         "place_rank": "30",
461         "category": "place",
462         "type": "house",
463         "importance": 0.62025
464       },
465       "bbox": [
466         26.1156689,
467         44.4354754,
468         26.1157689,
469         44.4355754
470       ],
471       "geometry": {
472         "type": "Point",
473         "coordinates": [
474           26.1157189,
475           44.4355254
476         ]
477       }
478     }
479   ]
480 }
481 ```
482
483 ##### GeocodeJSON
484
485 [https://nominatim.openstreetmap.org/search?q=%CE%91%CE%B3%CE%AF%CE%B1+%CE%A4%CF%81%CE%B9%CE%AC%CE%B4%CE%B1%2C+%CE%91%CE%B4%CF%89%CE%BD%CE%B9%CE%B4%CE%BF%CF%82%2C+Athens%2C+Greece&format=geocodejson](https://nominatim.openstreetmap.org/search?q=%CE%91%CE%B3%CE%AF%CE%B1+%CE%A4%CF%81%CE%B9%CE%AC%CE%B4%CE%B1%2C+%CE%91%CE%B4%CF%89%CE%BD%CE%B9%CE%B4%CE%BF%CF%82%2C+Athens%2C+Greece&format=geocodejson)
486
487 ```json
488 {
489   "type": "FeatureCollection",
490   "geocoding": {
491     "version": "0.1.0",
492     "attribution": "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright",
493     "licence": "ODbL",
494     "query": "Αγία Τριάδα, Αδωνιδος, Athens, Greece"
495   },
496   "features": [
497     {
498       "type": "Feature",
499       "properties": {
500         "geocoding": {
501           "type": "place_of_worship",
502           "label": "Αγία Τριάδα, Αδωνιδος, Άγιος Νικόλαος, 5º Δημοτικό Διαμέρισμα Αθηνών, Athens, Municipality of Athens, Regional Unit of Central Athens, Region of Attica, Attica, 11472, Greece",
503           "name": "Αγία Τριάδα",
504           "admin": null
505         }
506       },
507       "geometry": {
508         "type": "Point",
509         "coordinates": [
510           23.72949633941,
511           38.0051697
512         ]
513       }
514     }
515   ]
516 }
517 ```