参考网址:https://opendistro.github.io/for-elasticsearch-docs/docs/sql/ https://aws.amazon.com/cn/blogs/china/build-run-sql-plugin-open-distro-elasticsearch-oss/
构造测试数据
略
获取索引
λ curl -XGET http://127.0.0.1:9200/_cat/indices
yellow open index_test1 oYe-xTjQQJiOmsJkJr8SZg 1 1 10 0 4.8kb
查询数据
λ curl -XGET http://127.0.0.1:9200/index_test1/_search?size=2
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 10,
"relation": "eq"
},
"max_score": 1.0,
"hits": [{
"_index": "index_test1",
"_type": "type_test1",
"_id": "2vLrhnEBeYyL1elhVvpG",
"_score": 1.0,
"_source": {
"id": 0,
"name": "lucy0",
"age": 0,
"sex": 1
}
}
]
}
}
传入sql直接查询数据,linux单引号可行,windows需双引号
curl -XPOST http://127.0.0.1:9200/_opendistro/_sql -H "Content-Type: application/json" -d "{\"query\": \"SELECT * FROM index_test1\"}"
# 结果:
λ curl -XPOST http://127.0.0.1:9200/_opendistro/_sql -H "Content-Type: application/json" -d "{\"query\": \"SELECT * FRO M index_test1 limit 1\"}"
{
"schema": [
{
"name": "sex",
"type": "long"
},
{
"name": "name",
"type": "text"
},
{
"name": "id",
"type": "long"
},
{
"name": "age",
"type": "long"
}
],
"total": 10,
"datarows": [[
1,
"lucy0",
0,
0
]],
"size": 1,
"status": 200
}
url -H "Content-type: application/json" -XGET localhost:9200/_opendistro/_sql?sql=SELECT%20title%20FROM%20movies
待续