New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

es-mapping-to-schema

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

es-mapping-to-schema

Convert Elasticsearch mappings to Schema Inspector schemas

  • 1.0.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Elasticsearch Mapping to Schema Inspector schema

This allows you to convert an elasticsearch mapping, defined in JSON into a schema that works with Schema Inspector.

Install:

npm install --save es-mapping-to-schema

Use:

const MappingToSchema = require('es-mapping-to-schema');

const mapping = {
      _all:       {
        enabled: false
      },
      properties: {
        longThing:              {
          type: 'long'
        },
        doubleThing:            {
          type: 'double'
        },
        nonanalyzedStringThing: {
          type:  'string',
          index: 'not_analyzed'
        },
        variousTerm:            {
          type:   'string',
          fields: {
            raw:         {
              type:  'string',
              index: 'not_analyzed',
              store: true
            },
            normalized:  {
              type:     'string',
              analyzer: 'facet_analyzer'
            },
            lang_en:     {
              type:     'string',
              analyzer: 'english'
            },
            lang_en_raw: {
              type:     'string',
              analyzer: 'raw_diacritic_free'
            }
          }
        },
        customer:               {
          properties: {
            customerId: {
              type:  'string',
              index: 'not_analyzed'
            },
            projectId:  {
              type:  'string',
              index: 'not_analyzed'
            },
            localTime:  {
              type:   'date',
              format: 'dateOptionalTime'
            }
          }
        },
        selectors:              {
          type:              'nested',
          include_in_parent: true,
          properties:        {
            selector: {
              properties: {
                name:  {
                  type:   'string',
                  fields: {
                    raw:        {
                      type:  'string',
                      index: 'not_analyzed',
                      store: true
                    },
                    normalized: {
                      type:     'string',
                      analyzer: 'facet_analyzer'
                    }
                  }
                },
                value: {
                  type:   'string',
                  fields: {
                    raw: {
                      type:  'string',
                      index: 'not_analyzed',
                      store: true
                    }
                  }
                }
              }
            }
          }
        }
      }
    };
    
const schema = MappingToSchema(mapping);

const expectedSchema = {
     type:       'object',
     properties: {
       longThing:              {
         type: 'integer'
       },
       doubleThing:            {
         type: 'number'
       },
       nonanalyzedStringThing: {
         type:      'string',
         maxLength: 32766,
         rules:     ['trim']
       },
       customer:               {
         type:       'object',
         properties: {
           customerId: {
             type:      'string',
             maxLength: 32766,
             rules:     ['trim']
           },
           projectId:  {
             type:      'string',
             maxLength: 32766,
             rules:     ['trim']
           },
           localTime:  {
             type: 'date'
           }
         }
       },
       selectors:              {
         type:       'object',
         properties: {
           selector: {
             type:       'object',
             properties: {
               name:  {
                 type:      'string',
                 maxLength: 32766,
                 rules:     ['trim']
               },
               value: {
                 type:      'string',
                 maxLength: 32766,
                 rules:     ['trim']
               }
             }
           }
         }
       }
     }
   };
   
schema === expectedSchema; // true

Also supports specifying the optional and array properties, see tests for details.

FAQs

Package last updated on 05 Jul 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc