
com.github.jchanghong.elasticsearch.elasticsearchs.kt Maven / Gradle / Ivy
package com.github.jchanghong.elasticsearch
import cn.hutool.json.JSONUtil
import com.github.jchanghong.gson.jsonByPath
import com.github.jchanghong.gson.jsonToObject
import com.github.jchanghong.gson.toJsonStr
import com.github.jchanghong.http.OkHttps
import com.github.jchanghong.http.get
import com.github.jchanghong.http.postJson
object ElasticsearchHelper{
/** http://127.0.0.1:9200*/
var serverUrl="http://127.0.0.1:9200"
fun showTables(): String {
val postJson = OkHttps.httpClient.postJson("${serverUrl}/_sql?format=txt&pretty", """
{
"query": "show tables"
}
""".trimIndent())
return postJson
}
fun DESCRIBE(table :String): String {
val postJson = OkHttps.httpClient.postJson("${serverUrl}/_sql?format=txt&pretty", """
{
"query": "DESCRIBE $table"
}
""".trimIndent())
return postJson
}
fun queryForJson(sql:String): String {
val postJson = OkHttps.httpClient.postJson("${serverUrl}/_sql?format=json&pretty", """
{
"query": "$sql"
}
""".trimIndent())
// println(postJson)
val jsonToObject = postJson.jsonToObject
© 2015 - 2025 Weber Informatics LLC | Privacy Policy