Add Wikipedia/Wikidata Importance Ranking to an Existing Self-Hosted Nominatim Server on Ubuntu

After deploying a self-hosted Nominatim server, I noticed that search result ranking was different from the public Nominatim service.

For example, when searching for:

Taipei Main Station

the public Nominatim service returned this as the top result:

building/train_station
name: Taipei main station
lat/lon: 25.0477156, 121.5171139

However, before adding the importance data, my self-hosted Nominatim returned this as the top result:

railway/station
name: Taipei main station
lat/lon: 25.0462432, 121.5174745

The OSM objects existed in my local database, but the ranking data was different.

The reason was that my self-hosted Nominatim instance did not have Wikipedia/Wikidata-derived importance data.

In Nominatim, importance is not an OpenStreetMap tag. It is computed ranking metadata used by Nominatim to order search results when multiple places match a query. The main importance value is derived from Wikipedia page ranking. For places that do not have their own Wikipedia page, Nominatim falls back to a static value derived from the place’s search rank. Nominatim can also use secondary importance as a tie-breaker for places with very similar primary importance values.

In this post, I will add Wikipedia/Wikidata importance ranking data to an existing Nominatim installation.

This post assumes that Nominatim is already installed and working.


Related Post

This post continues from my previous OSM service setup guide:

That post covered the initial Nominatim and OSRM deployment. This post focuses only on adding Wikipedia/Wikidata importance ranking to the existing Nominatim database.


Existing Setup

In this setup, Nominatim is installed using a Python virtual environment.

The paths are:

Nominatim user:       nominatim
Project directory:   /srv/nominatim/nominatim-project
Virtual environment: /srv/nominatim/nominatim-venv
Database name:       nominatim

The Nominatim API is exposed through systemd:

nominatim.socket
nominatim.service

The normal Nominatim update is handled by:

nominatim-updates.timer
nominatim-updates.service

The existing update service runs:

/srv/nominatim/nominatim-venv/bin/nominatim replication --once

The existing update timer runs every day at 04:00.


  1. Download the Importance Files

Switch to the nominatim user:

sudo -u nominatim bash

Activate the virtual environment:

cd /srv/nominatim
. /srv/nominatim/nominatim-venv/bin/activate

Go to the Nominatim project directory:

cd /srv/nominatim/nominatim-project
export PROJECT_DIR=/srv/nominatim/nominatim-project

Download the importance files:

wget -O wikimedia-importance.csv.gz \
  https://nominatim.org/data/wikimedia-importance.csv.gz

wget -O secondary_importance.sql.gz \
  https://nominatim.org/data/wikimedia-secondary-importance.sql.gz

These files provide the external Wikipedia/Wikidata-derived ranking data used by the refresh command.


  1. Run a One-Time Importance Refresh

For this existing Nominatim database, I do not need to delete the database or import the Taiwan PBF file again.

I run the refresh outside the normal Nominatim update window. In my setup, the normal update runs daily at 04:00, so I avoid running this around that time.

Check that the normal update service is not currently running:

systemctl is-active nominatim-updates.service

If it returns:

inactive

then run the importance refresh.

Stay inside the nominatim shell and make sure the virtual environment is active:

cd /srv/nominatim
. /srv/nominatim/nominatim-venv/bin/activate

cd /srv/nominatim/nominatim-project
export PROJECT_DIR=/srv/nominatim/nominatim-project

Run the refresh:

nominatim refresh \
  --wiki-data \
  --secondary-importance \
  --importance \
  2>&1 | tee refresh-importance.log

In my Taiwan-only Nominatim database, the refresh quickly started importing the secondary importance data and Wikipedia article importance data. The longer part was this step:

Update importance values for database

In my later systemd test, the full importance refresh service finished successfully in about 16 minutes. The runtime may still vary depending on the server resources and database size.

After the refresh finishes, check the database:

nominatim admin --check-database

The important line is:

Checking for wikipedia/wikidata data ... OK

This confirms that the Wikipedia/Wikidata data exists in the Nominatim database.

Exit the nominatim shell:

exit

  1. Test Nominatim Search

From another machine, test the Nominatim HTTP API:

curl -G "https://osm.maksonlee.com/nominatim/search" \
  --data-urlencode "q=Taipei Main Station" \
  --data-urlencode "format=json" \
  --data-urlencode "limit=5" \
  --data-urlencode "accept-language=en" | jq

I use accept-language=en so the returned names and display names are easier to read in English.

After the refresh, the result should include meaningful importance values.

In my test, the top results included:

building/train_station
name: Taipei main station
importance: 0.4734860033637308
railway/station
name: Taipei main station
importance: 0.4734860033637308

Another related station object also had a meaningful importance value:

building/transportation
name: Taipei Main Station (Taoyuan Airport MRT)
importance: 0.3656661556590361

This confirms that the self-hosted Nominatim database now has Wikipedia/Wikidata-derived importance data.

However, do not expect Nominatim ranking to become identical to Google Maps. Nominatim is still an OSM-based geocoder, and application-specific ranking may still be needed.

For example, a transport app should still give extra weight to:

railway=station
public_transport=station
highway=bus_stop
railway=subway_entrance
TDX stations
TDX bus stops
known transport hubs

Nominatim importance helps, but it should not be the only ranking layer in an application backend.


  1. Create a Monthly Importance Refresh Script

Create a script:

sudo tee /usr/local/bin/update-nominatim-importance.sh > /dev/null << 'EOF'
#!/usr/bin/env bash
set -euo pipefail

PROJECT_DIR="/srv/nominatim/nominatim-project"
VENV="/srv/nominatim/nominatim-venv"
LOG_DIR="/var/log/nominatim"
DATE="$(date +%Y%m%d-%H%M%S)"
TMP_DIR="$(mktemp -d)"

cleanup() {
  rm -rf "$TMP_DIR"
}

trap cleanup EXIT

mkdir -p "$LOG_DIR"

echo "[1/6] Check normal Nominatim update service"

if systemctl is-active --quiet nominatim-updates.service; then
  echo "nominatim-updates.service is currently running."
  echo "Do not run the importance refresh at the same time as the normal Nominatim update."
  exit 1
fi

echo "[2/6] Download latest importance files"

wget -O "$TMP_DIR/wikimedia-importance.csv.gz" \
  https://nominatim.org/data/wikimedia-importance.csv.gz

wget -O "$TMP_DIR/secondary_importance.sql.gz" \
  https://nominatim.org/data/wikimedia-secondary-importance.sql.gz

echo "[3/6] Install importance files into project directory"

install -o nominatim -g nominatim -m 0644 \
  "$TMP_DIR/wikimedia-importance.csv.gz" \
  "$PROJECT_DIR/wikimedia-importance.csv.gz"

install -o nominatim -g nominatim -m 0644 \
  "$TMP_DIR/secondary_importance.sql.gz" \
  "$PROJECT_DIR/secondary_importance.sql.gz"

echo "[4/6] Refresh importance data"

sudo -u nominatim bash -c "
set -e
cd '$PROJECT_DIR'
. '$VENV/bin/activate'

nominatim refresh \
  --wiki-data \
  --secondary-importance \
  --importance
" 2>&1 | tee "$LOG_DIR/importance-refresh-$DATE.log"

echo "[5/6] Check database"

sudo -u nominatim bash -c "
set -e
cd '$PROJECT_DIR'
. '$VENV/bin/activate'
nominatim admin --check-database
"

echo "[6/6] Done"
EOF

Make it executable:

sudo chmod +x /usr/local/bin/update-nominatim-importance.sh

This script does not stop the Nominatim API.

It also does not stop the normal Nominatim update timer.

Instead, the script checks whether nominatim-updates.service is currently running. If the normal update service is active, the script exits and does not run the importance refresh.


  1. Run the Script Manually

Run it once manually:

sudo /usr/local/bin/update-nominatim-importance.sh

Check the script log:

sudo ls -lh /var/log/nominatim/

LATEST_LOG="$(sudo ls -t /var/log/nominatim/importance-refresh-*.log | head -n 1)"
echo "$LATEST_LOG"
sudo cat "$LATEST_LOG"

This log only contains the nominatim refresh output. When the script is run by systemd, the full service output is available from journalctl.


  1. Create a systemd Service

Create the service:

sudo tee /etc/systemd/system/nominatim-importance.service > /dev/null << 'EOF'
[Unit]
Description=Refresh Nominatim Wikipedia/Wikidata importance data
After=network-online.target postgresql.service
Wants=network-online.target

[Service]
Type=oneshot
ExecStart=/usr/local/bin/update-nominatim-importance.sh
StandardOutput=journal
StandardError=inherit
EOF

This service only runs the importance refresh script. It does not stop the existing Nominatim API service, socket, or update timer.


  1. Create a systemd Timer

Create the timer:

sudo tee /etc/systemd/system/nominatim-importance.timer > /dev/null << 'EOF'
[Unit]
Description=Run Nominatim importance refresh monthly

[Timer]
OnCalendar=Sun *-*-01..07 00:30
Persistent=true
Unit=nominatim-importance.service

[Install]
WantedBy=timers.target
EOF

This runs on the first Sunday of each month at 00:30.

I use 00:30 because my normal Nominatim update runs daily at 04:00, so the two jobs should not normally overlap.

Enable the timer:

sudo systemctl daemon-reload
sudo systemctl enable --now nominatim-importance.timer

Check the timers:

systemctl list-timers | grep nominatim

You should see both timers:

nominatim-updates.timer
nominatim-importance.timer

  1. Test the Monthly Service

Start the service manually:

sudo systemctl start nominatim-importance.service

Check the status:

systemctl status nominatim-importance.service --no-pager

The service should finish with status 0/SUCCESS.

In my test, systemctl status showed:

Active: inactive (dead)
Process: ... status=0/SUCCESS
Finished nominatim-importance.service
Consumed 45.726s CPU time over 16min 34.127s wall clock time

Check the journal logs:

journalctl -u nominatim-importance.service -n 100 --no-pager

Check the script logs:

sudo ls -lh /var/log/nominatim/

Did this guide save you time?

Support this site

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top