Registry / database / json-schema-to-es-mapping

json-schema-to-es-mapping

JSON →
library0.3.6jsnpmunverified

Convert JSON Schema definitions into Elasticsearch index mappings. Version 0.3.6 is the latest release (no frequent updates). This library supports most core Elasticsearch data types (string, numeric, boolean, date, range) and can handle nested objects, arrays, and $ref references. It differs from similar tools by providing simple functions like buildMappingsFor that wrap the mapping in an index-level structure. The package is ESM-only but also supports CommonJS via require. It does not handle the binary type or scaled_float. Suitable for developers who need to generate Elasticsearch mappings from existing JSON Schema without manual transformation.

npm install json-schema-to-es-mapping
INSTALL
IMPORT
SIG · JSON-SCHEMA-TO-ES-
J
json-schema-to-es-mapping
databasejavascriptv0.3.6
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

buildMappingsFor
import { buildMappingsFor } from 'json-schema-to-es-mapping'
const buildMappingsFor = require('json-schema-to-es-mapping').buildMappingsFor
Use named import with ES module syntax. CommonJS require works but is not the primary export style.
build
import { build } from 'json-schema-to-es-mapping'
import build from 'json-schema-to-es-mapping'
Default export is not available; must use named import for the build function.
default
const pkg = require('json-schema-to-es-mapping')
import pkg from 'json-schema-to-es-mapping'
There is no default export, so import default from this package is invalid. Use named imports or require.

Demonstrates converting a JSON Schema object into an Elasticsearch mappings object for an index named 'people'.

const schema = { $schema: "http://json-schema.org/draft-07/schema#", $id: "http://example.com/person.schema.json", title: "Person", description: "A person", type: "object", properties: { name: { description: "Name of the person", type: "string" }, age: { description: "Age of person", type: "number" } }, required: ["name"] }; const { buildMappingsFor } = require('json-schema-to-es-mapping'); const mappings = buildMappingsFor("people", schema); console.log(JSON.stringify(mappings, null, 2));
Debug
Known issues
gotchaPackage does not support the binary Elasticsearch datatype; binary fields in JSON Schema will be skipped or cause undefined behavior.
fix
Manually add binary type mappings outside this library.
affects: <=0.3.6
gotchaNumeric mapping may incorrectly infer types when range is not explicitly set; using min/max without range:true treats field as numeric range but may produce unexpected mapping.
fix
Set 'range: true' explicitly if you intend to use Elasticsearch range types.
affects: <=0.3.6
deprecatedThe library does not handle Elasticsearch scaled_float numeric type; it may be added in future but currently unsupported.
fix
Use a custom mapping for scaled_float fields.
affects: <=0.3.6
gotchaThe buildMappingsFor function returns an object with a nested 'mappings' key that may include only one index; for multi-index use you must call it multiple times.
fix
Iterate over indexes and build separate mappings, then combine manually.
affects: <=0.3.6
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'properties')
Passing a JSON schema that is missing a 'properties' or 'type' field at the top level.
fix
Ensure the schema has a top-level 'type: "object"' and a 'properties' object.
Error: Unsupported JSON Schema type: undefined or null
Encountered a property with no type specified or an unrecognized type.
fix
Set a valid Elasticsearch type (e.g., string, number, object) for every property in the schema.
ReferenceError: $ref resolution failed: ...
A $ref pointer references a definition that does not exist or is not defined in the schema.
fix
Include a 'definitions' key with matching definition objects, or use a JSON Schema that resolves all $ref.
Upgrade
Version history
0.3.6latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
4
Amazon
1
Resources
json-schema-to-es-mapping — npm install json-schema-to-es-mapping · libregistry