Git Product home page Git Product logo

Comments (2)

shi-yuan avatar shi-yuan commented on June 8, 2024 1

支持case when:

select a,case when c='1' then 'haha' when c='2' then 'book' else 'hbhb' end as gg from tbl_a group by a,gg

不过上面语句不支持,可以用script:

select
sum(script("","def df = Integer.parseInt(DateTimeFormatter.ofPattern('HH').withZone(ZoneId.systemDefault()).format(Instant.ofEpochMilli(doc['data_time'].value.getMillis())));if(df>0 && df<9){doc['data_value'].value} else {0}")) freeTime,
sum(script("","def df = Integer.parseInt(DateTimeFormatter.ofPattern('HH').withZone(ZoneId.systemDefault()).format(Instant.ofEpochMilli(doc['data_time'].value.getMillis())));if(df>9 && df<18){doc['data_value'].value} else {0}")) dayTime,
count(DISTINCT script("","DateTimeFormatter.ofPattern('yyyy-MM-dd').withZone(ZoneId.systemDefault()).format(Instant.ofEpochMilli(doc['data_time'].value.getMillis()))")) countDateTime,
sum(data_value) totalCount
from
table_name
{
  "from": 0,
  "size": 0,
  "_source": {
    "includes": [
      "sum",
      "sum",
      "count",
      "sum"
    ],
    "excludes": []
  },
  "aggregations": {
    "freeTime": {
      "sum": {
        "script": {
          "source": "def df = Integer.parseInt(DateTimeFormatter.ofPattern('HH').withZone(ZoneId.systemDefault()).format(Instant.ofEpochMilli(doc['data_time'].value.getMillis())));if(df>0 && df<9){doc['data_value'].value} else {0}",
          "lang": "painless"
        }
      }
    },
    "dayTime": {
      "sum": {
        "script": {
          "source": "def df = Integer.parseInt(DateTimeFormatter.ofPattern('HH').withZone(ZoneId.systemDefault()).format(Instant.ofEpochMilli(doc['data_time'].value.getMillis())));if(df>9 && df<18){doc['data_value'].value} else {0}",
          "lang": "painless"
        }
      }
    },
    "countDateTime": {
      "cardinality": {
        "script": {
          "source": "DateTimeFormatter.ofPattern('yyyy-MM-dd').withZone(ZoneId.systemDefault()).format(Instant.ofEpochMilli(doc['data_time'].value.getMillis()))",
          "lang": "painless"
        }
      }
    },
    "totalCount": {
      "sum": {
        "field": "data_value"
      }
    }
  }
}

from elasticsearch-sql.

TommyLemon avatar TommyLemon commented on June 8, 2024

@shi-yuan 希望能直接支持,这样能兼容更广泛的应用场景。
APIJSON 支持 SQL 及各种 SQL 方言,但不支持这个 script(看起来不是存储过程,而是类似 Java 的自定义脚本)。
目前 APIJSON 就是通过 elasticsearch-sql 来支持 Elasticsearch:
https://github.com/Tencent/APIJSON

from elasticsearch-sql.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.