cube.js elasticsearch 官方sql 扩展使用
  TEZNKK3IfmPf 2023年11月14日 35 0
  • es 环境
version: "3"
services: 
  es01:
    image: elasticsearch:7.3.2
    container_name: es01
   // 开启sql 以及认证
    environment:
      - "http.host=0.0.0.0"
      - "transport.host=localhost"
      - "network.host=0.0.0.0"
      - "http.cors.enabled=true"
      - "http.cors.allow-origin=*"
      - "xpack.ml.enabled=false"
      - "xpack.security.enabled=true"
      - "xpack.sql.enabled=true"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    ports:
      - 9200:9200

初始化账户(进入容器)

elasticsearch-setup-passwords  auto -v
  • es 数据
    app.js
 
const { Client } = require('@elastic/elasticsearch')
const client = new Client({ node: 'http://elastic:ed824a5iPV33lrO7MOz0@localhost:9200' })
 
async function run () {
  // Let's start by indexing some data
  await client.index({
    index: 'game',
    // type: '_doc', // uncomment this line if you are using Elasticsearch ≤ 6
    body: {
      character: 'Ned Stark',
      quote: 'Winter is coming.'
    }
  })
 
  await client.index({
    index: 'game',
    // type: '_doc', // uncomment this line if you are using Elasticsearch ≤ 6
    body: {
      character: 'Daenerys Targaryen',
      quote: 'I am the blood of the dragon.'
    }
  })
 
  await client.index({
    index: 'game',
    // type: '_doc', // uncomment this line if you are using Elasticsearch ≤ 6
    body: {
      character: 'Tyrion Lannister',
      quote: 'A mind needs books like a sword needs a whetstone.'
    }
  })
 
  // here we are forcing an index refresh, otherwise we will not
  // get any result in the consequent search
  await client.indices.refresh({ index: 'game' })
 
  // Let's search!
  const { body } = await client.search({
    index: 'game',
    // type: '_doc', // uncomment this line if you are using Elasticsearch ≤ 6
    body: {
      query: {
        match: { quote: 'winter' }
      }
    }
  })
 
  console.log(body.hits.hits)
}
 
run().catch(console.log)

cube.js 配置

.env

CUBEJS_DB_URL=http://elastic:ed824a5iPV33lrO7MOz0@localhost:9200
CUBEJS_DB_ELASTIC_QUERY_FORMAT=json
CUBEJS_DEV_MODE=true
CUBEJS_DB_TYPE=elasticsearch
CUBEJS_API_SECRET=b9a87765c28b91d570e51647c3e7cbb5a71364147bdfbef65ffa307808ef9128b98142883a541e48a8b8517d0e02d7e8344ac694c29e7b0f09a3ee0df10755d8

package.json

{
  "name": "myappdemo",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "dev": "./node_modules/.bin/cubejs-server"
  },
  "template": "docker",
  "templateVersion": "0.26.44",
  "devDependencies": {
    "@cubejs-backend/cubestore-driver": "^0.28.8",
    "@cubejs-backend/elasticsearch-driver": "^0.28.8",
    "@cubejs-backend/server": "^0.28.8"
  }
}

访问效果

cube.js elasticsearch 官方sql 扩展使用

 

 


cube.js elasticsearch 官方sql 扩展使用

 

 

说明

对于database 的处理有点问题,多了main,都是可以使用的

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月14日 0

暂无评论

推荐阅读
  TEZNKK3IfmPf   2024年05月17日   47   0   0 dremiosqltable
  TEZNKK3IfmPf   2024年04月26日   55   0   0 java数据库sql
  TEZNKK3IfmPf   2024年05月17日   51   0   0 sqlmysql
  TEZNKK3IfmPf   2024年05月17日   38   0   0 sqlcube
  TEZNKK3IfmPf   2024年04月26日   29   0   0 javasql
  TEZNKK3IfmPf   2024年04月19日   52   0   0 sqlUser
TEZNKK3IfmPf