]> 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 | 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 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 `place_id`s you want to skip.
238 This can be used to retrieve additional search results. For example, if a
239 previous query only returned a few results, then including those here would
240 cause the search to return other, less accurate, matches (if possible).
241
242 | Parameter | Value | Default |
243 |-----------| ----- | ------- |
244 | viewbox   | `<x1>,<y1>,<x2>,<y2>` | _unset_ |
245
246 Boost parameter which focuses the search on the given area.
247 Any two corner points of the box are accepted as long as they make a proper
248 box. `x` is longitude, `y` is latitude.
249
250 | Parameter | Value  | Default |
251 |-----------| -----  | ------- |
252 | bounded   | 0 or 1 | 0       |
253
254 When set to 1, then it turns the 'viewbox' parameter (see above) into
255 a filter parameter, excluding any results outside the viewbox.
256
257 When `bounded=1` is given and the viewbox is small enough, then an amenity-only
258 search is allowed. Give the special keyword for the amenity in square
259 brackets, e.g. `[pub]` and a selection of objects of this type is returned.
260 There is no guarantee that the result returns all objects in the area.
261
262
263 ### Polygon output
264
265 | Parameter | Value  | Default |
266 |-----------| -----  | ------- |
267 | polygon_geojson | 0 or 1 | 0 |
268 | polygon_kml     | 0 or 1 | 0 |
269 | polygon_svg     | 0 or 1 | 0 |
270 | polygon_text    | 0 or 1 | 0 |
271
272 Add the full geometry of the place to the result output. Output formats
273 in GeoJSON, KML, SVG or WKT are supported. Only one of these
274 options can be used at a time.
275
276 | Parameter | Value  | Default |
277 |-----------| -----  | ------- |
278 | polygon_threshold | floating-point number | 0.0 |
279
280 When one of the polygon_* outputs is chosen, return a simplified version
281 of the output geometry. The parameter describes the
282 tolerance in degrees with which the geometry may differ from the original
283 geometry. Topology is preserved in the geometry.
284
285 ### Other
286
287 | Parameter | Value  | Default |
288 |-----------| -----  | ------- |
289 | email     | valid email address | _unset_ |
290
291 If you are making large numbers of request please include an appropriate email
292 address to identify your requests. See Nominatim's
293 [Usage Policy](https://operations.osmfoundation.org/policies/nominatim/) for more details.
294
295 | Parameter | Value  | Default |
296 |-----------| -----  | ------- |
297 | dedupe    | 0 or 1 | 1       |
298
299 Sometimes you have several objects in OSM identifying the same place or
300 object in reality. The simplest case is a street being split into many
301 different OSM ways due to different characteristics. Nominatim will
302 attempt to detect such duplicates and only return one match. Setting
303 this parameter to 0 disables this deduplication mechanism and
304 ensures that all results are returned.
305
306 | Parameter | Value  | Default |
307 |-----------| -----  | ------- |
308 | debug     | 0 or 1 | 0       |
309
310 Output assorted developer debug information. Data on internals of Nominatim's
311 "search loop" logic, and SQL queries. The output is HTML format.
312 This overrides the specified machine readable format.
313
314
315 ## Examples
316
317
318 ##### XML with KML polygon
319
320 * [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)
321
322 ```xml
323 <?xml version="1.0" encoding="UTF-8" ?>
324 <searchresults timestamp="Tue, 08 Aug 2023 15:45:41 +00:00"
325                attribution="Data © OpenStreetMap contributors, ODbL 1.0. http://osm.org/copyright"
326                querystring="135 pilkington avenue, birmingham"
327                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"
328                exclude_place_ids="125279639">
329   <place place_id="125279639"
330          osm_type="way"
331          osm_id="90394480"
332          lat="52.5487921"
333          lon="-1.8164308"
334          boundingbox="52.5487473,52.5488481,-1.8165130,-1.8163464"
335          place_rank="30"
336          address_rank="30"
337          display_name="135, Pilkington Avenue, Maney, Sutton Coldfield, Wylde Green, Birmingham, West Midlands Combined Authority, England, B72 1LH, United Kingdom"
338          class="building"
339          type="residential"
340          importance="9.999999994736442e-08">
341     <geokml>
342       <Polygon>
343         <outerBoundaryIs>
344           <LinearRing>
345             <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>
346           </LinearRing>
347         </outerBoundaryIs>
348       </Polygon>
349     </geokml>
350     <house_number>135</house_number>
351     <road>Pilkington Avenue</road>
352     <hamlet>Maney</hamlet>
353     <town>Sutton Coldfield</town>
354     <village>Wylde Green</village>
355     <city>Birmingham</city>
356     <ISO3166-2-lvl8>GB-BIR</ISO3166-2-lvl8>
357     <state_district>West Midlands Combined Authority</state_district>
358     <state>England</state>
359     <ISO3166-2-lvl4>GB-ENG</ISO3166-2-lvl4>
360     <postcode>B72 1LH</postcode>
361     <country>United Kingdom</country>
362     <country_code>gb</country_code>
363   </place>
364 </searchresults>
365 ```
366
367 ##### JSON with SVG polygon
368
369 [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)
370
371 ```json
372 [
373   {
374     "address": {
375       "ISO3166-2-lvl4": "DE-BE",
376       "borough": "Mitte",
377       "city": "Berlin",
378       "country": "Deutschland",
379       "country_code": "de",
380       "historic": "Kommandantenhaus",
381       "house_number": "1",
382       "neighbourhood": "Friedrichswerder",
383       "postcode": "10117",
384       "road": "Unter den Linden",
385       "suburb": "Mitte"
386     },
387     "boundingbox": [
388       "52.5170798",
389       "52.5173311",
390       "13.3975116",
391       "13.3981577"
392     ],
393     "class": "historic",
394     "display_name": "Kommandantenhaus, 1, Unter den Linden, Friedrichswerder, Mitte, Berlin, 10117, Deutschland",
395     "importance": 0.8135042058306902,
396     "lat": "52.51720765",
397     "licence": "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright",
398     "lon": "13.397834399325466",
399     "osm_id": 15976890,
400     "osm_type": "way",
401     "place_id": 108681845,
402     "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",
403     "type": "house"
404   }
405 ]
406 ```
407
408 ##### JSON with address details
409
410 [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)
411
412 ```json
413 [
414   {
415     "address": {
416       "ISO3166-2-lvl4": "DE-BE",
417       "borough": "Mitte",
418       "city": "Berlin",
419       "country": "Deutschland",
420       "country_code": "de",
421       "neighbourhood": "Sprengelkiez",
422       "postcode": "13347",
423       "road": "Lindower Straße",
424       "shop": "Ditsch",
425       "suburb": "Wedding"
426     },
427     "addresstype": "shop",
428     "boundingbox": [
429       "52.5427201",
430       "52.5427654",
431       "13.3668619",
432       "13.3669442"
433     ],
434     "category": "shop",
435     "display_name": "Ditsch, Lindower Straße, Sprengelkiez, Wedding, Mitte, Berlin, 13347, Deutschland",
436     "importance": 9.99999999995449e-06,
437     "lat": "52.54274275",
438     "licence": "Data © OpenStreetMap contributors, ODbL 1.0. http://osm.org/copyright",
439     "lon": "13.36690305710228",
440     "name": "Ditsch",
441     "osm_id": 437595031,
442     "osm_type": "way",
443     "place_id": 204751033,
444     "place_rank": 30,
445     "type": "bakery"
446   }
447 ]
448 ```
449
450 ##### GeoJSON
451
452 [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)
453
454 ```json
455 {
456   "type": "FeatureCollection",
457   "licence": "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright",
458   "features": [
459     {
460       "type": "Feature",
461       "properties": {
462         "place_id": "35811445",
463         "osm_type": "node",
464         "osm_id": "2846295644",
465         "display_name": "17, Strada Pictor Alexandru Romano, Bukarest, Bucharest, Sector 2, Bucharest, 023964, Romania",
466         "place_rank": "30",
467         "category": "place",
468         "type": "house",
469         "importance": 0.62025
470       },
471       "bbox": [
472         26.1156689,
473         44.4354754,
474         26.1157689,
475         44.4355754
476       ],
477       "geometry": {
478         "type": "Point",
479         "coordinates": [
480           26.1157189,
481           44.4355254
482         ]
483       }
484     }
485   ]
486 }
487 ```
488
489 ##### GeocodeJSON
490
491 [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)
492
493 ```json
494 {
495   "type": "FeatureCollection",
496   "geocoding": {
497     "version": "0.1.0",
498     "attribution": "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright",
499     "licence": "ODbL",
500     "query": "Αγία Τριάδα, Αδωνιδος, Athens, Greece"
501   },
502   "features": [
503     {
504       "type": "Feature",
505       "properties": {
506         "geocoding": {
507           "type": "place_of_worship",
508           "label": "Αγία Τριάδα, Αδωνιδος, Άγιος Νικόλαος, 5º Δημοτικό Διαμέρισμα Αθηνών, Athens, Municipality of Athens, Regional Unit of Central Athens, Region of Attica, Attica, 11472, Greece",
509           "name": "Αγία Τριάδα",
510           "admin": null
511         }
512       },
513       "geometry": {
514         "type": "Point",
515         "coordinates": [
516           23.72949633941,
517           38.0051697
518         ]
519       }
520     }
521   ]
522 }
523 ```