npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@koopjs/provider-elastic-sql

v1.0.1

Published

Experimental provider for elastic/opensearch

Downloads

1

Readme

koop-provider-elastic-sql

Provider to fetch data in elastic/opensearch datastores through the SQL API. This provider leverages the SQL API exclusively, and as such, it is limited by the capabilities of that API.

Data considerations

In order to gain the greatest efficiency from this provider, each document/record in your dataset should have a unique-indentifier that is a property of the document/record. This is important, because even though Elastic will create its own _id field as part of a document's metadata, metadata fields are not accessible via the SQL API.

If your data has a geometry and you want leverage Elastic's geo-filter capability (and you should), the geometry field needs to be mapped in your Elasticsearch Index as a geopoint or geoshape.

A key aspect of working with Elastic is that its API will only return a maximum of 10000 records in any request. If your dataset has more than 10000 records and you request doesn't result in a set that is less than 10000 records, the results will be truncated. This limits the ability to paginate. To reduce the risk of truncation you should always use a unique-identifier property, a mapped geometry field, and registered the provider with the index mappings for these fields (more on this below).

Usage

Register the provider with Koop:

const Koop = require('@koopjs/koop-core');
const koop = new Koop({ logLevel: 'info'});
const elasticSqlProvider = require('@koopjs/provider-elastic-sql');

koop.register(elasticSqlProvider, { conn, idFieldMap, geometryFieldMap });

Registration parameters

conn (required)

An object that contains connection details for the target Elastic cluster. See the Elastic documentation for details.

idFieldMap (optional)

An key/value populated object that serves as a lookup/dictionary for the unique-identifier field of a given Elastic index. For example, if your index is named "my-index", and the documents in the that index have a field called "some-id-prop" that can be used as a unique-identifier, then the idFieldMap would look like:

const idFieldMap = {
  'my-index': 'some-id-prop'
};

The idFieldMap can have multiple key/value pairs if your Elastic cluster has multiple indicies.

If you omit the idFieldMap, filtering requested with the GeoService objectsIds parameter will not be executed by the Elastic SQL API.

geometryFieldMap (optional)

An key/value populated object that serves as a lookup/dictionary for the geopoint/geoshape field of a given Elastic index. For example, if your index is named "my-index", and the geometry of a document is stored in a geoshape field called "the-geo-prop", then the geometryFieldMap would look like:

const idFieldMap = {
  'my-index': 'the-geo-prop'
};

While elastic has no limit on the number of geo-fields per document, conversion of a document to GeoJSON requires that we identify a single field as the definitive geometry. The geometryFieldMap can have multiple key/value pairs if your Elastic cluster has multiple indicies.

If you omit the geometryFieldMap, the GeoJSON produced by the provider will not include a geometry. In addition, geometry filtering will not be executed by the Elastic instance.

Route parameters

id

Once registered with Koop, the provide will expose routes with an id parameter. For example:

/elastic-sql/rest/services/:id/FeatureServer

The id parameter should be filled with the name of the Elastic index you are targeting. So if you wished to query the fires document-index on you Elastic instance, you would make a request to:

/elastic-sql/rest/services/fires/FeatureServer/0/query

Demo

The repository includes a demonstration project. To run the demo you will need Docker installed on your computer. Once installed you can following the steps below to create a local Elastic instance and load it with sample data:

> npm install

> cd demo

# use Docker to run Elastic/Kibana
> docker-compose up -d

# load sample data; this will create an Elastc index named "fires"
> node loader.js 

# start the Koop application
> node demo.js