创建索引
createIndex()
创建索引,需要传入两个参数。EDb()
可以传入一个数据源的名称,默认是第一个数据源
- @param
index
索引 - @param
body
结构 (index: string, body?: DBOBJECT)
createIndex()
const esConfig = {
host: '127.0.0.1',
port: 9200
}
import { EDb } from 'think-ts-db'
export default defineEventHandler(async (event) => {
EDb(esConfig).createIndex('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).createIndex('goods', {
settings: {
number_of_shards: 1,
number_of_replicas: 1
},
mappings: {
properties: {
field1: { type: "text" },
field2: { type: "keyword" },
field3: { type: "integer" }
}
}
})
return true
})