Skip to content

Configure Nominatim to expose date tags #949

Closed
Closed

Description

@1ec5

Search results from the Nominatim API currently do not indicate start and end dates according to the element’s start_date=* and end_date=* tags.

Steps to reproduce

This Nominatim search for “Loveland” includes this result. The extratags object looks like this:

{
  "wikidata": "Q843993",
  "wikipedia": "en:Loveland, Ohio",
  "name:etymology": "James Loveland",
  "name:etymology:wikidata": "Q8308802"
}

even though the node is tagged start_date=1876-05-16 and end_date=1961-07-25.

Impact

The dates are important information for disambiguating search results (#431) without needing to hard-code date ranges in the name=* tag (related to #793). These tags would also be necessary for automatically adjusting the time slider when selecting a feature from the search results list (#196). One idea for searching by date would rely on filtering results by date on the client side – this would also require exposing the date tags.

Diagnosis

The API’s JSON response format includes an extratags property that serves as a catch-all for miscellaneous tags that the client can read without having to send a separate OSM API request or Overpass API query. ohm-website is already setting extratags=1 in its Nominatim requests, but by default, Nominatim is only including certain keys that are common in OSM, such as ele=*, population=*, and wikidata=*.

Based on this documentation, we can include the date tags by providing a custom import style. We’d copy import-full.lua to the project directory, then set the NOMINATIM_IMPORT_STYLE variable to the Lua script’s file path, either in a .env file or as an environment variable. The Lua script needs to have something like this in it:

flex.set_prefilters {
    -- Source tags are very common but not used by Nominatim. Deleting them speeds up indexing.
    delete_keys = {'source', 'source:*', '*:source'},
    -- Date tags are essential for disambiguation.
    extra_keys = {'start_date', 'start_date:edtf', 'end_date', 'end_date:edtf'}
}

Activity

  1. 1ec5 commented on Feb 7, 2025

    @1ec5
    MemberAuthor

    Based on this documentation, we can include the date tags by providing a custom import style. We’d copy import-full.lua to the project directory, then set the NOMINATIM_IMPORT_STYLE variable to the Lua script’s file path, either in a .env file or as an environment variable.

    The NOMINATIM_IMPORT_STYLE environment variable needs to be set in this template:

    https://github.com/OpenHistoricalMap/ohm-deploy/blob/5b72c8213524801edf39c666c0fdb13dd997e0c5/values.production.template.yaml#L664

    which parallels an example environment file in osm-seed:

    https://github.com/developmentseed/osm-seed/blob/49245d21c7ef9a9314c63397914d71f1b5fd235d/envs/.env.nominatim.example

  2. Rub21 commented on Feb 7, 2025

    @Rub21
    Member

    which would be the value for NOMINATIM_IMPORT_STYLE, I can add in the configuration and tested in staging, also we are using nominatim mediagis/nominatim:4.1 https://github.com/developmentseed/osm-seed/blob/49245d21c7ef9a9314c63397914d71f1b5fd235d/images/nominatim/Dockerfile#L1 ,

    there are more recent versions for nominatim , https://hub.docker.com/r/mediagis/nominatim/tags

  3. 1ec5 commented on Feb 7, 2025

    @1ec5
    MemberAuthor

    The import style mechanism was the same in v4.1, but that version used a different .style format:

    • Make a copy of import-extratags.style (which is the default style)
    • Add the following entry to the JSON file:
      {
          "keys" : ["start_date", "start_date:edtf", "end_date", "end_date:edtf"],
          "values" : {
              "" : "extra"
          }
      }
    • Upload the file somewhere, such as nominatim-ui alongside our existing address-levels.json override or somewhere in ohm-deploy.
    • Set NOMINATIM_IMPORT_STYLE to the path to this raw file.

    For a more recent version of Nominatim:

    • Make a file similar to import-full.lua but with the addition of:
      flex.set_prefilters {
          -- Source tags are very common but not used by Nominatim. Deleting them speeds up indexing.
          delete_keys = {'source', 'source:*', '*:source'},
          -- Date tags are essential for disambiguation.
          extra_keys = {'start_date', 'start_date:edtf', 'end_date', 'end_date:edtf'}
      }
    • Upload the file somewhere, such as nominatim-ui alongside our existing address-levels.json override or somewhere in ohm-deploy.
    • Set NOMINATIM_IMPORT_STYLE to the path to this raw file.

    Note that I haven’t tested any of this, so it might need some trial and error.

  4. Rub21 commented on Feb 17, 2025

    @Rub21
    Member

    I have updated the nominatim to 4.5 in staging, that including the extratags.

    Image Image

    Here is the API: https://nominatim-api.staging.openhistoricalmap.org/. There are updates on the front end that still need to be worked on at https://nominatim-staging.openhistoricalmap.org/.

  5. self-assigned this
    on Feb 17, 2025
  6. moved this from In Progress to On Staging + Tested (Dan?) in OpenHistoricalMap Dev Planningon Feb 25, 2025
  7. danrademacher commented on Feb 25, 2025

    @danrademacher

    This is done and deployed. This unblocks #431 most immediately

  8. moved this from On Staging + Tested (Dan?) to Done in OpenHistoricalMap Dev Planningon Feb 25, 2025
  9. added theissue type on Mar 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions