Querying the Overpass API for Villages

I have been able to query all cities and towns from Overpass, but it seems there are too many villages to get a query without timing out. Is there any way to get similar results to what Overpass gives by downloading the entire 60gb database file?
Or is there any way to split up Overpass queries in a easy way?

This is my query right now which looks impossible to run:
node[place=“village”];foreach(out;is_in;area._[admin_level~“2|4”];out body;

Thanks for any help!

Try increasing the timeout and adding qt option to output.
out body qt;

Thanks for the information. It seems without the for each for areas it’s much faster. But I need to know the provice/country for each one. I haven’t found any other way except the foreach loop on the out which seems to be very slow… otherwise I’d need to query the API too many times to do each , one by one.

Did you know that there are almost a million village nodes out there in OSM? http://taginfo.openstreetmap.org/tags/place=village
On the contrary, there are only about 400 level 2 admin levels and about 4000 level 4.

I’d suggest to turn your whole query upside down, i.e. use those admin levels as input for the foreach loop, rather than a list of 1 Mio. village nodes. When testing, start with a tiny number of areas, adjust timeout as needed.

BTW: Running your query for 1 mio. villages one by one will get you blocked very soon, as it violates the usage policy of max 10’000 queries per day.

I had no idea how many there are until now.

I ended up splitting by level 2 area ids and looped for level 4 only in the query with ID only output.
It’s working pretty good but a couple of countries timed out. I think querying by level 4 like you said would be much better, and still below the 10,000 limit.

Thanks a lot!