Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/egebalci/golang-struct-to-elastic-mapping

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/egebalci/golang-struct-to-elastic-mapping

  • v0.0.0-20230131093404-d402bddbcfb6
  • Source
  • Go
  • Socket score

Version published
Created
Source

Golang struct to elastic mapping

Examples

package main

type Alias struct {
    Alias string `json:"alias" es:"type:keyword,index:true"`
    Name  string `json:"name" es:"type:text"`
}

type Company struct {
    ID    int    `json:"id" es:"index:true"`
    Alias string `json:"alias" es:"type:keyword,index:true"`
    Name  string `json:"name" es:"type:text"`
}

type Vacancy struct {
    ID              int     `json:"id" es:"index:true"`
    Title           string  `json:"title" es:"type:text"`
    Description     string  `json:"description" es:"type:text"`
    Company         Company `json:"company"`
    RequiredSkills  []Alias `json:"required_skills"`
    PreferredSkills []Alias `json:"preferred_skills"`
    DesiredSkills   []Alias `json:"desired_skills"`
}
{
  "mappings": {
    "properties": {
      "id": {
        "type": "integer",
        "index": true
      },
      "title": {
        "type": "text"
      },
      "description": {
        "type": "text"
      },
      "company": {
        "type": "nested",
        "properties": {
          "id": {
            "type": "integer",
            "index": true
          },
          "alias": {
            "type": "keyword",
            "index": true
          },
          "name": {
            "type": "text"
          }
        }
      },
      "required_skills": {
        "type": "nested",
        "properties": {
          "alias": {
            "type": "keyword",
            "index": true
          },
          "name": {
            "type": "text"
          }
        }
      },
      "preferred_skills": {
        "type": "nested",
        "properties": {
          "alias": {
            "type": "keyword",
            "index": true
          },
          "name": {
            "type": "text"
          }
        }
      },
      "desired_skills": {
        "type": "nested",
        "properties": {
          "alias": {
            "type": "keyword",
            "index": true
          },
          "name": {
            "type": "text"
          }
        }
      }
    }
  }
}
package main

import (
	"testing"

	"github.com/YaroslavPodorvanov/golang-struct-to-elastic-mapping/generator"

	"github.com/stretchr/testify/require"
)

func TestExample(t *testing.T) {
	// language=JSON
	const expected = `...`

	var result, err = generator.Generate(&Vacancy{})

	require.NoError(t, err)
	require.Equal(t, expected, string(result))
}

Original

  • Issue
  • Mapping template

Elasticsearch Guide

FAQs

Package last updated on 31 Jan 2023

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