Elasticsearch之CURL命令的GET


 

 

  這是個查詢命令。

 

 

前期博客

Elasticsearch之CURL命令的PUT和POST對比

 

 

 

 

   1、

  以上是根據員工id查詢。

  即在任意的查詢字符串中添加pretty參數,es可以得到易於我們識別的json結果。(這一點必須要會)

[hadoop@master elasticsearch-2.4.0]$ curl -XGET http://master:9200/zhouls/user/1
{"_index":"zhouls","_type":"user","_id":"1","_version":1,"found":true,"_source":{"name" : "john"  , "age" : 28}}[hadoop@master elasticsearch-2.4.0]$ 
[hadoop@master elasticsearch-2.4.0]$ 
[hadoop@master elasticsearch-2.4.0]$ curl -XGET http://master:9200/zhouls/user/1?pretty
{
  "_index" : "zhouls",
  "_type" : "user",
  "_id" : "1",
  "_version" : 1,
  "found" : true,
  "_source" : {
    "name" : "john",
    "age" : 28
  }
}
[hadoop@master elasticsearch-2.4.0]$ 
[hadoop@master elasticsearch-2.4.0]$ 

 

 

 

 

 

  2、由此,可見,檢索文檔中的一部分,可以只查詢,只需要顯式部分字段。

[hadoop@master elasticsearch-2.4.0]$ curl -XGET 'http://master:9200/zhouls/user/1?_source=name,age&pretty'
{
  "_index" : "zhouls",
  "_type" : "user",
  "_id" : "1",
  "_version" : 1,
  "found" : true,
  "_source" : {
    "age" : 28,
    "name" : "john"
  }
}
[hadoop@master elasticsearch-2.4.0]$ curl -XGET 'http://master:9200/zhouls/user/1?_source=name&pretty'
{
  "_index" : "zhouls",
  "_type" : "user",
  "_id" : "1",
  "_version" : 1,
  "found" : true,
  "_source" : {
    "name" : "john"
  }
}
[hadoop@master elasticsearch-2.4.0]$ 

 

 

 

 

  3、查詢指定索引庫的指定類型的所有數據

[hadoop@master elasticsearch-2.4.0]$ curl -XGET 'http://master:9200/zhouls/user/_search'
{"took":78,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":4,"max_score":1.0,"hits":[{"_index":"zhouls","_type":"user","_id":"2","_score":1.0,"_source":{"name" : "john"  , "age" : 28}},{"_index":"zhouls","_type":"user","_id":"1","_score":1.0,"_source":{"name" : "john"  , "age" : 28}},{"_index":"zhouls","_type":"user","_id":"AVz5Q9u7U8bDb6QDgbDS","_score":1.0,"_source":{"name" : "john"}},{"_index":"zhouls","_type":"user","_id":"3","_score":1.0,"_source":{"name" : "john"  , "age" : 28}}]}}[hadoop@master elasticsearch-2.4.0]$ 
[hadoop@master elasticsearch-2.4.0]$ 
[hadoop@master elasticsearch-2.4.0]$ curl -XGET 'http://master:9200/zhouls/user/_search?pretty'
{
  "took" : 105,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 4,
    "max_score" : 1.0,
    "hits" : [ {
      "_index" : "zhouls",
      "_type" : "user",
      "_id" : "2",
      "_score" : 1.0,
      "_source" : {
        "name" : "john",
        "age" : 28
      }
    }, {
      "_index" : "zhouls",
      "_type" : "user",
      "_id" : "1",
      "_score" : 1.0,
      "_source" : {
        "name" : "john",
        "age" : 28
      }
    }, {
      "_index" : "zhouls",
      "_type" : "user",
      "_id" : "AVz5Q9u7U8bDb6QDgbDS",
      "_score" : 1.0,
      "_source" : {
        "name" : "john"
      }
    }, {
      "_index" : "zhouls",
      "_type" : "user",
      "_id" : "3",
      "_score" : 1.0,
      "_source" : {
        "name" : "john",
        "age" : 28
      }
    } ]
  }
}
[hadoop@master elasticsearch-2.4.0]$ 

 

 

 

 

 

 

 

   4、根據條件進行查詢

[hadoop@master elasticsearch-2.4.0]$ curl -XGET 'http://master:9200/zhouls/user/_search?q=name:john'
{"took":109,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":4,"max_score":1.0,"hits":[{"_index":"zhouls","_type":"user","_id":"1","_score":1.0,"_source":{"name" : "john"  , "age" : 28}},{"_index":"zhouls","_type":"user","_id":"AVz5Q9u7U8bDb6QDgbDS","_score":1.0,"_source":{"name" : "john"}},{"_index":"zhouls","_type":"user","_id":"2","_score":0.30685282,"_source":{"name" : "john"  , "age" : 28}},{"_index":"zhouls","_type":"user","_id":"3","_score":0.30685282,"_source":{"name" : "john"  , "age" : 28}}]}}[hadoop@master elasticsearch-2.4.0]$ 
[hadoop@master elasticsearch-2.4.0]$ 
[hadoop@master elasticsearch-2.4.0]$ curl -XGET 'http://master:9200/zhouls/user/_search?q=age:28'
{"took":54,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":3,"max_score":1.4054651,"hits":[{"_index":"zhouls","_type":"user","_id":"1","_score":1.4054651,"_source":{"name" : "john"  , "age" : 28}},{"_index":"zhouls","_type":"user","_id":"2","_score":0.30685282,"_source":{"name" : "john"  , "age" : 28}},{"_index":"zhouls","_type":"user","_id":"3","_score":0.30685282,"_source":{"name" : "john"  , "age" : 28}}]}}[hadoop@master elasticsearch-2.4.0]$ 
[hadoop@master elasticsearch-2.4.0]$ 
[hadoop@master elasticsearch-2.4.0]$ 

 

 

 

 

 

官網

https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM