One - One Code All

Blog Content

ElasticSearch opendistro插件的CURL方式的SQL查询

ElasticSearch   2020-04-18 21:21:33

基础测试

  • 参考网址: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
    }
  • 如果是GET方式,需要对SQL语句进行URL 编码

    url -H "Content-type: application/json" -XGET localhost:9200/_opendistro/_sql?sql=SELECT%20title%20FROM%20movies
  • 待续




上一篇:MAC里“微软雅黑”字体标准体和粗体无法同时使用问题的解决方法
下一篇:github快速下载方法及软件资源快速下载方法

The minute you think of giving up, think of the reason why you held on so long.