curl命令 增刪改查 (windows10系統下)

 

 

1.創建索引庫

curl -XPUT http://localhost:9200/test/

2.刪除索引庫

curl -XDELETE http://localhost:9200/test/

3.插入數據

curl -H "Content-type: application/json" -XPOST localhost:9200/test/5 -d "{\"age\":\"12\",\"user_name\":\"zhangs\",\"name\":\"linda\",\"disc\":{\"a\":\"1\",\"b\":\"2\"}}"

4.修改數據

curl -H "Content-type: application/json" -XPUT localhost:9200/test/5/sr6sxW4BITjAt6wGz_Uq -d "{\"name\":\"update name\",\"disc\":{\"a\":\"1111\",\"b\":\"2\"}}"

注意:(1)sr6sxW4BITjAt6wGz_Uq 是es自動生成的id 

          (2)id 不能重複

也可以手動規定id  

curl -H "Content-type: application/json" -XPUT localhost:9200/test/5/1 -d "{\"name\":\"testid\",\"disc\":{\"a\":\"222\",\"b\":\"2222\"}}"

5.查詢

curl -H "Content-type: application/json" -XGET localhost:9200/test/5/1?pretty   (沒有使用倒排索引)

注意:pretty  格式化返回的數據

curl -H "Content-type: application/json" -XGET localhost:9200/test/5/_search?q=disc.a=1

注意:_search 表示 查詢索引內的數據

(1)一個參數的查詢:

curl -H "Content-type: application/json" -XGET localhost:9200/test/5/_search?pretty -d "{\"query\":{\"match\":{\"name\":\"testid\"}}}"

(2)對多個field進行查詢:要查詢的是"linda" 在 "age","gender","name"這個幾個屬性的範圍內

multi_match 表示多重匹配

curl -H "Content-type: application/json" -XGET localhost:9200/test/5/_search?pretty -d  "{\"query\":{\"multi_match\":{\"query\":\"linda\",\"fields\":[\"age\",\"gender\",\"name\"],\"operator\":\"and\"}}}"

(3)組合查詢   

多個term對多個field發起查詢:bool(boolean)

組合查詢:must,must_not,should

must+must =交集,must+must_not=差集,should+should=並集

交集:curl -H "Content-type: application/json" -XGET localhost:9200/test/5/_search?pretty -d "{\"query\":{\"bool\":{\"must\":{\"match\":{\"age\":\"12\"}},\"must\":{\"match\":{\"user_name\":\"zhaoqn\"}}}}}"    age必須是12  user_name必須是zhaoqn

(上述的json格式在window10下面執行json格式轉換異常,linux去掉  "\" 應該好用)

差集:curl -H "Content-type: application/json" -XGET localhost:9200/test/5/_search?pretty -d "{\"query\":{\"bool\":{\"must\":{\"match\":{\"age\":\"12\"}},\"must_not\":{\"match\":{\"user_name\":\"zhaoqn\"}}}}}"  age必須是12  user_name必須不是zhaoqn

區間查詢:curl -H "Content-type: application/json" -XGET localhost:9200/test/5/_search?pretty -d "{\"query\":{\"bool\":{\"must\":{\"term\":{\"user_name\":\"zhaoqn\"}},\"must_not\":{\"range\":{\"age\":{\"from\":14,\"to\":24}}}}}}"  user_name是zhaoqn並且age不在14到24之間

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章