• Stars
    star
    209
  • Rank 188,325 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 10 years ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

HTTP API for Pelias Geocoder

A modular, open-source search engine for our world.

Pelias is a geocoder powered completely by open data, available freely to everyone.

Local Installation · Cloud Webservice · Documentation · Community Chat

What is Pelias?
Pelias is a search engine for places worldwide, powered by open data. It turns addresses and place names into geographic coordinates, and turns geographic coordinates into places and addresses. With Pelias, you’re able to turn your users’ place searches into actionable geodata and transform your geodata into real places.

We think open data, open source, and open strategy win over proprietary solutions at any part of the stack and we want to ensure the services we offer are in line with that vision. We believe that an open geocoder improves over the long-term only if the community can incorporate truly representative local knowledge.

Pelias API Server

This is the API server for the Pelias project. It's the service that runs to process user HTTP requests and return results as GeoJSON by querying Elasticsearch and the other Pelias services.

Documentation

Full documentation for the Pelias API lives in the pelias/documentation repository.

Install Dependencies

The Pelias API has no dependencies beyond Node.js

See Pelias Software requirements for the supported and recommended versions.

npm install

scripts

The API ships with several convenience commands (runnable via npm):

  • npm start: start the server
  • npm test: run unit tests
  • npm run ciao: run functional tests (this requires that the server be running)
  • npm run docs: generate API documentation
  • npm run coverage: generate code coverage reports
  • npm run config: dump the configuration to the command line, which is useful for debugging configuration issues

Configuration via pelias-config

To run the API with your custom config, specify the location of the config file in the environment variable PELIAS_CONFIG like so:

PELIAS_CONFIG=/path/to/pelias.json npm run start

The API recognizes the following properties under the top-level api key in your pelias.json config file:

parameter required default description
services no Service definitions for point-in-polygon, libpostal, placeholder, and interpolation services. For a description of when different Pelias services are recommended or required, see our services documentation.
defaultParameters.focus.point.lon
defaultParameters.focus.point.lat
no default coordinates for focus point
targets.auto_discover no true Should sources and layers be automatically discovered by querying Elasticsearch at process startup. (See more info in the Custom sources and layers section below).
targets.auto_discover_required no false If set to true, type mapping discovery failures will result in a fatal error. This means a valid connection to a working Elasticsearch cluster with a Pelias index is required on startup. Setting this to true can help prevent issues such as incorrect configuration in production environments
targets.layers_by_source
targets.source_aliases
targets.layer_aliases
no custom values for which sources and layers the API accepts (See more info in the Custom sources and layers section below). We recommend using the targets.auto_discover:true configuration instead of setting these manually.
customBoosts no {} Allows configuring boosts for specific sources and layers, in order to influence result order. See Configurable Boosts below for details
autocomplete.exclude_address_length no 0 As a performance optimization, this optional filter excludes results from the 'address' layer for any queries where the character length of the 'subject' portion of the parsed_text is equal to or less than this many characters in length. Addresses are usually the bulk of the records in Elasticsearch, and searching across all of them for very short text inputs can be slow, with little benefit. Consider setting this to 1 or 2 if you have several million addresses in Pelias.
indexName no pelias name of the Elasticsearch index to be used when building queries
attributionURL no (autodetected) The full URL to use for the attribution link returned in all Pelias responses. Pelias will attempt to autodetect this host, but it will often be incorrect if, for example, there is a proxy between Pelias and its users. This parameter allows setting a specific URL to avoid any such issues
accessLog no name of the format to use for access logs; may be any one of the predefined values in the morgan package. Defaults to "common"; if set to false, or an otherwise falsy value, disables access-logging entirely.
relativeScores no true if set to true, confidence scores will be normalized, realistically at this point setting this to false is not tested or desirable
exposeInternalDebugTools no true Exposes several debugging tools, such as the ability to enable Elasticsearch explain mode, that may come at a performance cost or expose sensitive infrastructure details. Not recommended if the Pelias API is open to the public.

A good starting configuration file includes this section (fill in the service and Elasticsearch hosts as needed):

{
  "esclient": {
    "hosts": [{
      "host": "elasticsearch"
    }]
  },
  "api": {
    "services": {
      "placeholder": {
        "url": "http://placeholder:4100"
      },
      "libpostal": {
        "url": "http://libpostal:8080"
      },
      "pip": {
        "url": "http://pip-service:4200",
        "timeout": 1000,
        "retries": 2
      },
      "interpolation": {
        "url": "http://interpolation:4300"
      }
    }
  },
  "logger": {
    "level": "debug"
  }
}

The timeout and retry values, as show in in the pip service section, are optional but configurable for all services (see pelias/microservice-wrapper for more details).

Custom sources and layers

Pelias allows importing your own data with custom values for source and layer.

Custom sources and layers are automatically detected on startup of the API. To disable this behavior (not recommended), set targets.auto_discover to false in your pelias.json.

The auto_discover functionality sends a request to Elasticsearch in order to automatically discover sources and layers from Elasticsearch when the API server starts-up.

In setups with lots of data (hundreds of millions of records loaded), and low CPU resources, the query sent to Elasticsearch can take several seconds to execute, potentially impacting the performance of other queries hitting Elasticsearch at the same time. The query is cached in Elasticsearch for subsequent requests.

In the rare event this causes issues, the following configuration options can be set to configure sources and layers by hand.

layers_by_source

This parameter tells Pelias what type of records it can expect a given datasource to have. Anything put here will extend the default configuration which handles all the open data project Pelias supports out of the box. The parameter is an object where your custom source names are the keys, and the list of layers in that source are the values in an array. For example, if you have two custom sources, mysource which contains addresses and countries, and mysource2 containing neighbourhoods, the following would work well:

"api": {
  "targets": {
    "layers_by_source": {
      "mysource": ["address", "country"],
      "mysource2": ["neighbourhood"]
    }
  }
}

source_aliases

An optional list of alternate names for sources. These 'aliases' are a convenient way to provide a short alias for a more verbose source name. An alias may refer to one or more sources. The keys on the left side represent a previously undefined 'alias', while the values in the array on the right refer to sources previously defined in "layers_by_source".

For example, to create an alias that allows conveniently searching the two open data projects who's name starts with "Open", use the following configuration:

{
  "api": {
    "targets": {
      "source_aliases": {
        "opensomething": [ "openstreetmap", "openaddresses" ]
    }
  }
}

layer_aliases

An optional list of alternate names for layers. These 'aliases' are a convenient way to provide a short alias for a more verbose layer name. An alias may refer to one or more layers. The keys on the left side represent a previously undefined 'alias', while the values in the array on the right refer to layers previously defined in "layers_by_source"

For example, to create a layer alias water that represents all the water layer types supported by Pelias:

{
  "api": {
    "targets": {
      "layer_aliases": {
        "water": [ "ocean", "marinearea" ]
    }
  }
}

Custom Boosts

The customBoosts config section allows influencing the sorting of results returned from most Pelias queries. Every Pelias record has a source and layer value, and this section allows prioritizing certain sources and layers.

First, keep in mind:

  1. This will not affect all Pelias queries. In particular, when using the /v1/search endpoint, queries for administrative areas (cities, countries, etc) will likely not be affected
  2. Custom boosts allow influencing results, but not completely controlling them. Very good matches that aren't in a boosted source or layer may still be returned first.

The basic form of the configuration looks like this:

{
  "api":
    "customBoosts": {
      "layer": {
        "layername": 5,
        "layername2": 3
      },
      "source": {
        "sourcename": 5
      }
    }
  }
}

There are subsections for both layer and source, and each subsection must be an object. Keys in those objects represent the sources and layers to be boosted, and the value associated with those keys must be a numeric value.

Boost values are essentially multipliers, so values greater than 1 will cause a source or layer to be returned more often, and higher in results. Boosts of the value 1 are the same as no boost, and boosts between 0 and 1 will de-prioritize matching records.

Recommended boost values are between 1 and 5. Higher boosts are likely to cause unexpected impact without really improving results much.

Configuration via Environment variable

Most Pelias configuration is done through pelias-config, however the API has additional environment variables that affect its operation:

environment variable default description
HOST undefined The network interface the Pelias API will bind to. Defaults to whatever the current Node.js default is, which is currently to listen on all interfaces. See the Node.js Net documentation for more info.
PORT 3100 The TCP port the Pelias API will use for incoming network connections.

Contributing

Please fork and pull request against upstream master on a feature branch. Pretty please; provide unit tests and script fixtures in the test directory.

Unit tests

You can run the unit test suite using the command:

$ npm test

HTTP tests

We have another set of tests which are used to test the HTTP API layer, these tests send expected HTTP requests and then assert that the responses coming back have the correct geoJSON format and HTTP status codes.

You can run the HTTP test suite using the command:

$ npm run ciao

Note: some of the tests in this suite fail when no data is present in the index, there is a small set of test documents provided in ./test/ciao_test_data which can be inserted in order to avoid these errors.

To inject dummy data in to your local index:

$ node test/ciao_test_data.js

You can confirm the dummy data has been inserted with the command:

$ curl localhost:9200/pelias/_count?pretty
{
  "count" : 9,
  ...
}

Continuous Integration

CI tests every release against all supported Node.js versions.

More Repositories

1

pelias

Pelias is a modular open-source geocoder using Elasticsearch.
Twig
3,052
star
2

placeholder

stand-alone coarse geocoder
JavaScript
303
star
3

docker

Run the Pelias geocoder in docker containers, including example projects.
Shell
287
star
4

documentation

All things documentation for Pelias
217
star
5

leaflet-plugin

Add Pelias geocoding to your Leaflet map.
JavaScript
189
star
6

pbf2json

An OpenStreetMap pbf parser which exports json, allows you to cherry-pick tags and handles denormalizing ways and relations. Available as a standalone binary and comes with a convenient npm wrapper.
Go
129
star
7

openstreetmap

Import pipeline for OSM in to Pelias
JavaScript
107
star
8

polygon-lookup

Fast point-in-polygon intersection for large numbers of polygons.
JavaScript
71
star
9

interpolation

global street address interpolation service (beta)
JavaScript
54
star
10

openaddresses

Pelias import pipeline for OpenAddresses.
JavaScript
46
star
11

geonames

Import pipeline for geonames in to Pelias
JavaScript
43
star
12

parser

natural language classification engine for geocoding
JavaScript
41
star
13

schema

elasticsearch schema files and tooling
JavaScript
38
star
14

libpostal-service

Dockerfile for libpostal-service based on the Who's on First implementation
Dockerfile
33
star
15

spatial

ALPHA: geographic data service backed by spatialite
JavaScript
29
star
16

whosonfirst

Importer for Who's on First gazetteer
JavaScript
26
star
17

pelias-android-sdk

Android sdk for pelias
Java
20
star
18

csv-importer

Import arbitrary data in CSV format to Pelias
JavaScript
17
star
19

polylines

Pelias import pipeline for polyline (road network) data.
JavaScript
17
star
20

pip-service

Pelias point-in-polygon-service
JavaScript
15
star
21

query

geospatial queries used by the pelias api
JavaScript
12
star
22

terraform-elasticsearch

Terraform scripts for running an Elasticsearch cluster
HCL
10
star
23

pelias-ios-sdk

Interact with Mapzen's search & geocoding service
Swift
9
star
24

wof-admin-lookup

Who's on First Admin Lookup for the Pelias Geocoder
JavaScript
9
star
25

config

Configuration file for Pelias
JavaScript
8
star
26

dashboard

Pelias dashboard built with the Dashing framework
JavaScript
7
star
27

scripts-batch-search

JavaScript
6
star
28

model

Pelias data models
JavaScript
6
star
29

transit

Load transit landmarks into the Pelias geocoder
JavaScript
6
star
30

acceptance-tests

Pelias API acceptance tests
4
star
31

presentation

Pelias related talks and presentations.
JavaScript
4
star
32

postal-cities

Scripts to generate mappings of postal codes to 'last line' postal localities (postal cities)
JavaScript
4
star
33

labels

Pelias Label generation
JavaScript
4
star
34

fuzzy-tester

A fuzzy testing library for geocoding
JavaScript
4
star
35

microservice-wrapper

JavaScript
4
star
36

docker-baseimage

Pelias Docker Baseimage
Dockerfile
3
star
37

wof

WhosOnFirst tools
JavaScript
3
star
38

dbclient

Database client for Pelias import pipelines
JavaScript
3
star
39

design

Branding & graphic design guidelines and assets
2
star
40

sorting

JavaScript
2
star
41

loadtest

Scripts for loadtesting pelias
JavaScript
2
star
42

woflint

WhosOnFirst document/collection linter
JavaScript
1
star
43

mars-importer

Importer for Martian data
JavaScript
1
star
44

docker-valhalla-baseimage

Pelias Docker Baseimage with Valhalla additionally installed
Shell
1
star
45

blacklist-stream

Pelias document blacklist stream
JavaScript
1
star
46

analysis

text analysis libraries (work in progress)
JavaScript
1
star
47

ci-tools

Tools for manging CI builds used in other repositories
Shell
1
star