]> git.openstreetmap.org Git - nominatim.git/blob - docs/api/Search.md
update documentation
[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 | Parameter | Value | Default |
140 |-----------| ----- | ------- |
141 | entrances | 0 or 1 | 0 |
142
143 When set to 1, include the tagged entrances in the result.
144
145
146 ### Language of results
147
148 | Parameter | Value | Default |
149 |-----------| ----- | ------- |
150 | accept-language | browser language string | content of "Accept-Language" HTTP header |
151
152 Preferred language order for showing search results. This may either be
153 a simple comma-separated list of language codes or have the same format
154 as the ["Accept-Language" HTTP header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language).
155
156 !!! tip
157     First-time users of Nominatim tend to be confused that they get different
158     results when using Nominatim in the browser versus in a command-line tool
159     like wget or curl. The command-line tools
160     usually don't send any Accept-Language header, prompting Nominatim
161     to show results in the local language. Browsers on the contrary always
162     send the currently chosen browser language.
163
164 ### Result restriction
165
166 There are two ways to influence the results. *Filters* exclude certain
167 kinds of results completely. *Boost parameters* only change the order of the
168 results and thus give a preference to some results over others.
169
170 | Parameter | Value | Default |
171 |-----------| ----- | ------- |
172 | countrycodes | comma-separated list of country codes | _unset_ |
173
174 Filter that limits the search results to one or more countries.
175 The country code must be the
176 [ISO 3166-1alpha2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) code
177 of the country, e.g. `gb` for the United Kingdom, `de` for Germany.
178
179 Each place in Nominatim is assigned to one country code based
180 on OSM country boundaries. In rare cases a place may not be in any country
181 at all, for example, when it is in international waters. These places are
182 also excluded when the filter is set.
183
184 !!! Note
185     This parameter should not be confused with the 'country' parameter of
186     the structured query. The 'country' parameter contains a search term
187     and will be handled with some fuzziness. The `countrycodes` parameter
188     is a hard filter and as such should be preferred. Having both parameters
189     in the same query will work. If the parameters contradict each other,
190     the search will come up empty.
191
192 | Parameter | Value | Default |
193 |-----------| ----- | ------- |
194 | layer     | comma-separated list of: `address`, `poi`, `railway`, `natural`, `manmade` | _unset_ (no restriction) |
195
196 The layer filter allows to select places by themes.
197
198 The `address` layer contains all places that make up an address:
199 address points with house numbers, streets, inhabited places (suburbs, villages,
200 cities, states tec.) and administrative boundaries.
201
202 The `poi` layer selects all point of interest. This includes classic POIs like
203 restaurants, shops, hotels but also less obvious features like recycling bins,
204 guideposts or benches.
205
206 The `railway` layer includes railway infrastructure like tracks.
207 Note that in Nominatim's standard configuration, only very few railway
208 features are imported into the database.
209
210 The `natural` layer collects features like rivers, lakes and mountains while
211 the `manmade` layer functions as a catch-all for features not covered by the
212 other layers.
213
214 | Parameter | Value | Default |
215 |-----------| ----- | ------- |
216 | featureType | one of: `country`, `state`, `city`, `settlement` | _unset_ |
217
218 The featureType allows to have a more fine-grained selection for places
219 from the address layer. Results can be restricted to places that make up
220 the 'state', 'country' or 'city' part of an address. A featureType of
221 `settlement` selects any human inhabited feature from 'state' down to
222 'neighbourhood'.
223
224 When featureType is set, then results are automatically restricted
225 to the address layer (see above).
226
227 !!! tip
228     Instead of using the featureType filters `country`, `state` or `city`,
229     you can also use a structured query without the finer-grained parameters
230     amenity or street.
231
232 | Parameter | Value | Default |
233 |-----------| ----- | ------- |
234 | exclude_place_ids | comma-separated list of ids (OSM IDs where possible, otherwise place_ids) |
235
236 If you do not want certain OSM objects to appear in the search
237 result, give a comma separated list of the ids you want to skip.
238
239 Each entry may be one of:
240
241 * a Nominatim internal `place_id` (for example `125279639`)
242 * an OSM object reference in the form `<osm_type><osm_id>` where `<osm_type>` is one of `N` (node), `W` (way) or `R` (relation), for example `N107775`
243
244 Usage of OSM IDs is recommended because they are server independent. `place_id`s are stil required for results without an OSM object reference (for example, postcodes and countries). When a street is excluded via its OSM ID, then interpolations and TIGER data derived from that street are excluded as well.
245
246 This can be used to retrieve additional search results. For example, if a
247 previous query only returned a few results, then including those here would
248 cause the search to return other, less accurate, matches (if possible).
249
250 | Parameter | Value | Default |
251 |-----------| ----- | ------- |
252 | viewbox   | `<x1>,<y1>,<x2>,<y2>` | _unset_ |
253
254 Boost parameter which focuses the search on the given area.
255 Any two corner points of the box are accepted as long as they make a proper
256 box. `x` is longitude, `y` is latitude.
257
258 | Parameter | Value  | Default |
259 |-----------| -----  | ------- |
260 | bounded   | 0 or 1 | 0       |
261
262 When set to 1, then it turns the 'viewbox' parameter (see above) into
263 a filter parameter, excluding any results outside the viewbox.
264
265 When `bounded=1` is given and the viewbox is small enough, then an amenity-only
266 search is allowed. Give the special keyword for the amenity in square
267 brackets, e.g. `[pub]` and a selection of objects of this type is returned.
268 There is no guarantee that the result returns all objects in the area.
269
270
271 ### Polygon output
272
273 | Parameter | Value  | Default |
274 |-----------| -----  | ------- |
275 | polygon_geojson | 0 or 1 | 0 |
276 | polygon_kml     | 0 or 1 | 0 |
277 | polygon_svg     | 0 or 1 | 0 |
278 | polygon_text    | 0 or 1 | 0 |
279
280 Add the full geometry of the place to the result output. Output formats
281 in GeoJSON, KML, SVG or WKT are supported. Only one of these
282 options can be used at a time.
283
284 | Parameter | Value  | Default |
285 |-----------| -----  | ------- |
286 | polygon_threshold | floating-point number | 0.0 |
287
288 When one of the polygon_* outputs is chosen, return a simplified version
289 of the output geometry. The parameter describes the
290 tolerance in degrees with which the geometry may differ from the original
291 geometry. Topology is preserved in the geometry.
292
293 ### Other
294
295 | Parameter | Value  | Default |
296 |-----------| -----  | ------- |
297 | email     | valid email address | _unset_ |
298
299 If you are making large numbers of request please include an appropriate email
300 address to identify your requests. See Nominatim's
301 [Usage Policy](https://operations.osmfoundation.org/policies/nominatim/) for more details.
302
303 | Parameter | Value  | Default |
304 |-----------| -----  | ------- |
305 | dedupe    | 0 or 1 | 1       |
306
307 Sometimes you have several objects in OSM identifying the same place or
308 object in reality. The simplest case is a street being split into many
309 different OSM ways due to different characteristics. Nominatim will
310 attempt to detect such duplicates and only return one match. Setting
311 this parameter to 0 disables this deduplication mechanism and
312 ensures that all results are returned.
313
314 | Parameter | Value  | Default |
315 |-----------| -----  | ------- |
316 | debug     | 0 or 1 | 0       |
317
318 Output assorted developer debug information. Data on internals of Nominatim's
319 "search loop" logic, and SQL queries. The output is HTML format.
320 This overrides the specified machine readable format.
321
322
323 ## Examples
324
325
326 ##### XML with KML polygon
327
328 * [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)
329
330 ```xml
331 <?xml version="1.0" encoding="UTF-8" ?>
332 <searchresults timestamp="Tue, 08 Aug 2023 15:45:41 +00:00"
333                attribution="Data © OpenStreetMap contributors, ODbL 1.0. http://osm.org/copyright"
334                querystring="135 pilkington avenue, birmingham"
335                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=W90394480&amp;format=xml"
336                exclude_place_ids="W90394480">
337   <place place_id="125279639"
338          osm_type="way"
339          osm_id="90394480"
340          lat="52.5487921"
341          lon="-1.8164308"
342          boundingbox="52.5487473,52.5488481,-1.8165130,-1.8163464"
343          place_rank="30"
344          address_rank="30"
345          display_name="135, Pilkington Avenue, Maney, Sutton Coldfield, Wylde Green, Birmingham, West Midlands Combined Authority, England, B72 1LH, United Kingdom"
346          class="building"
347          type="residential"
348          importance="9.999999994736442e-08">
349     <geokml>
350       <Polygon>
351         <outerBoundaryIs>
352           <LinearRing>
353             <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>
354           </LinearRing>
355         </outerBoundaryIs>
356       </Polygon>
357     </geokml>
358     <house_number>135</house_number>
359     <road>Pilkington Avenue</road>
360     <hamlet>Maney</hamlet>
361     <town>Sutton Coldfield</town>
362     <village>Wylde Green</village>
363     <city>Birmingham</city>
364     <ISO3166-2-lvl8>GB-BIR</ISO3166-2-lvl8>
365     <state_district>West Midlands Combined Authority</state_district>
366     <state>England</state>
367     <ISO3166-2-lvl4>GB-ENG</ISO3166-2-lvl4>
368     <postcode>B72 1LH</postcode>
369     <country>United Kingdom</country>
370     <country_code>gb</country_code>
371   </place>
372 </searchresults>
373 ```
374
375 ##### JSON with SVG polygon
376
377 [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)
378
379 ```json
380 [
381   {
382     "address": {
383       "ISO3166-2-lvl4": "DE-BE",
384       "borough": "Mitte",
385       "city": "Berlin",
386       "country": "Deutschland",
387       "country_code": "de",
388       "historic": "Kommandantenhaus",
389       "house_number": "1",
390       "neighbourhood": "Friedrichswerder",
391       "postcode": "10117",
392       "road": "Unter den Linden",
393       "suburb": "Mitte"
394     },
395     "boundingbox": [
396       "52.5170798",
397       "52.5173311",
398       "13.3975116",
399       "13.3981577"
400     ],
401     "class": "historic",
402     "display_name": "Kommandantenhaus, 1, Unter den Linden, Friedrichswerder, Mitte, Berlin, 10117, Deutschland",
403     "importance": 0.8135042058306902,
404     "lat": "52.51720765",
405     "licence": "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright",
406     "lon": "13.397834399325466",
407     "osm_id": 15976890,
408     "osm_type": "way",
409     "place_id": 108681845,
410     "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",
411     "type": "house"
412   }
413 ]
414 ```
415
416 ##### JSON with address details
417
418 [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)
419
420 ```json
421 [
422   {
423     "address": {
424       "ISO3166-2-lvl4": "DE-BE",
425       "borough": "Mitte",
426       "city": "Berlin",
427       "country": "Deutschland",
428       "country_code": "de",
429       "neighbourhood": "Sprengelkiez",
430       "postcode": "13347",
431       "road": "Lindower Straße",
432       "shop": "Ditsch",
433       "suburb": "Wedding"
434     },
435     "addresstype": "shop",
436     "boundingbox": [
437       "52.5427201",
438       "52.5427654",
439       "13.3668619",
440       "13.3669442"
441     ],
442     "category": "shop",
443     "display_name": "Ditsch, Lindower Straße, Sprengelkiez, Wedding, Mitte, Berlin, 13347, Deutschland",
444     "importance": 9.99999999995449e-06,
445     "lat": "52.54274275",
446     "licence": "Data © OpenStreetMap contributors, ODbL 1.0. http://osm.org/copyright",
447     "lon": "13.36690305710228",
448     "name": "Ditsch",
449     "osm_id": 437595031,
450     "osm_type": "way",
451     "place_id": 204751033,
452     "place_rank": 30,
453     "type": "bakery"
454   }
455 ]
456 ```
457
458 ##### GeoJSON
459
460 [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)
461
462 ```json
463 {
464   "type": "FeatureCollection",
465   "licence": "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright",
466   "features": [
467     {
468       "type": "Feature",
469       "properties": {
470         "place_id": "35811445",
471         "osm_type": "node",
472         "osm_id": "2846295644",
473         "display_name": "17, Strada Pictor Alexandru Romano, Bukarest, Bucharest, Sector 2, Bucharest, 023964, Romania",
474         "place_rank": "30",
475         "category": "place",
476         "type": "house",
477         "importance": 0.62025
478       },
479       "bbox": [
480         26.1156689,
481         44.4354754,
482         26.1157689,
483         44.4355754
484       ],
485       "geometry": {
486         "type": "Point",
487         "coordinates": [
488           26.1157189,
489           44.4355254
490         ]
491       }
492     }
493   ]
494 }
495 ```
496
497 ##### GeocodeJSON
498
499 [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)
500
501 ```json
502 {
503   "type": "FeatureCollection",
504   "geocoding": {
505     "version": "0.1.0",
506     "attribution": "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright",
507     "licence": "ODbL",
508     "query": "Αγία Τριάδα, Αδωνιδος, Athens, Greece"
509   },
510   "features": [
511     {
512       "type": "Feature",
513       "properties": {
514         "geocoding": {
515           "type": "place_of_worship",
516           "label": "Αγία Τριάδα, Αδωνιδος, Άγιος Νικόλαος, 5º Δημοτικό Διαμέρισμα Αθηνών, Athens, Municipality of Athens, Regional Unit of Central Athens, Region of Attica, Attica, 11472, Greece",
517           "name": "Αγία Τριάδα",
518           "admin": null
519         }
520       },
521       "geometry": {
522         "type": "Point",
523         "coordinates": [
524           23.72949633941,
525           38.0051697
526         ]
527       }
528     }
529   ]
530 }
531 ```