elasticsearch-model

1.0.2 • Public • Published

elasticsearch-model

easy model builder for elasticsearch

Getting Started

npm i elasticsearch-model 

Usage

const { Client } = require('@elastic/elasticsearch')
const client = new Client({ node: 'http://localhost:30100' })

const {
    t,
    ESModel,
} = require('elasticsearch-model')

class Model extends ESModel {

    custom () {
    }
}

// createdAt and updatedAt are both required

const mapping = t.Mapping({
    hello: t.KEYWORD,
    createdAt: t.DATE,
    updatedAt: t.DATE,
})

// Model

const name = 'doc'

const options = {
    client,
    index: name,
    type: name,
    mapping,
}

const model = new Model(options)

// model.updateMapping()

// Template
const name = 'log'

const options = {
    client,
    index: name,
    type: name,
    mapping,
}

const template = new Model(options)
const model = template.toModel('2019')

// template.updateTemplate()

Test

npm test

/elasticsearch-model/

    Package Sidebar

    Install

    npm i elasticsearch-model

    Weekly Downloads

    3

    Version

    1.0.2

    License

    ISC

    Unpacked Size

    20.1 kB

    Total Files

    6

    Last publish

    Collaborators

    • fanlia