Skip to content

添加文档


addDocument()

根据索引添加文档,需要传入两个参数。EDb() 可以传入一个数据源的名称,默认是第一个数据源

  • @param index 索引
  • @param body 结构 (index: string, body: DBOBJECT)

addDocument()

const esConfig = {
  host: '127.0.0.1',
  port: 9200
}

import { EDb } from 'think-ts-db'
export default defineEventHandler(async (event) => {
    EDb(esConfig).addDocument('goods', {
      settings: {
        number_of_shards: 1,
        number_of_replicas: 1
      },
      mappings: {
        properties: {
          field1: { type: "text" },
          field2: { type: "keyword" },
          field3: { type: "integer" }
        }
      }
    })
    return true
})
const esConfig = {
  host: '127.0.0.1',
  port: 9200
}

import { EDb } from 'think-ts-db'
export default defineEventHandler(async (event) => {
    EDb(esConfig).addDocument('goods', {
      settings: {
        number_of_shards: 1,
        number_of_replicas: 1
      },
      mappings: {
        properties: {
          field1: { type: "text" },
          field2: { type: "keyword" },
          field3: { type: "integer" }
        }
      }
    })
    return true
})

备案号:冀ICP备20015584号-2