- 添加一個index,指定分片是3,副本是1
curl -XPUT "http://10.10.110.125:9200/test_ods" -d'
{
"settings" : {
"number_of_shards" : 3,
"number_of_replicas" : 1
}
}'
- 删除一個index:
##使用以下的請求來删除索引:
curl -XDELETE "http://10.10.110.125:9200/my_indexs"
##你也可以用下面的方式删除多個索引
curl -XDELETE "http://10.10.110.125:9200/index_one,index_two"
curl -XDELETE "http://10.10.110.125:9200/index_*"
##你甚至可以删除所有索引
curl -XDELETE "http://10.10.110.125:9200/_all"
- 檢視es中的所有的索引(index)
http://10.10.110.125:9200/_all?pretty
- 檢視iteblog在es中的結構
http://10.10.110.125:9200/iteblog
- 檢視iteblog在es中的結構,位址加 ?pretty字尾,會格式化結果
http://10.10.110.125:9200/iteblog/?pretty
- 搜尋所有的索引文檔
http://10.10.110.125:9200/_search?&pretty
- 檢索文檔的一部分
http://10.10.110.125:9200/_search?_source=id,name&pretty
- 檢查index=iteblog type=iteblog id=AVmVzHLjCXGWba78sTXU的文檔。
http://10.10.110.125:9200/iteblog/iteblog/AVmVzHLjCXGWba78sTXU?pretty
http://10.10.110.125:9200/iteblog/iteblog/AVmVzHLjCXGWba78sTXU?_source=id,name&pretty
- 或者你隻想得到_source字段而不要其他的中繼資料,你可以這樣請求:
curl XGET http://10.10.110.125:9200/iteblog/iteblog/AVmVzHLjCXGWba78sTXU/_source?pretty
curl -i -XGET http://10.10.110.125:9200/iteblog/iteblog/AVmVzHLjCXGWba78sTXU/_source?pretty
- 檢查文檔是否存在,傳回200 OK狀态如果你的文檔存在
curl -i -XHEAD http://10.10.110.125:9200/iteblog/iteblog/AVmVzHLjCXGWba78sTXU/_source?pretty
- 向ods 索引 userinfo類型中添加一個id=10001的文檔
curl -XPUT "http://10.10.110.125:9200/ods/userinfo/10001" -d'
{
"username": "張三",
"age": "122",
"sex": "男"
}'
- 向ods 索引 jieshao類型中添加一個id為自動生成的文檔
curl -XPOST "http://10.10.110.125:9200/ods/jieshao" -d'
{
"title": "My second blog entry",
"text": "Still trying this out",
"date": "2014/01/01"
}'
- 檢視自動生成ID的文檔
curl http://10.10.110.125:9200/ods/jieshao/AVmWuI9ACXGWba78sTXm?pretty
##修改ID對應文檔的值,修改的後該文檔的版本_version會加1
curl -XPUT "http://10.10.110.125:9200/ods/jieshao/AVmWuI9ACXGWba78sTXm" -d'
{
"title": "My second blog entry2",
"text": "Still trying this out2",
"date": "2014/01/02"
}'
ES中文檔搜尋
1.空搜尋
最基本的搜尋API表單是空搜尋(empty search),它沒有指定任何的查詢條件,隻傳回叢集索引中的所有文檔:
http://10.10.110.125:9200/_search?&pretty
2. 在索引ods的所有類型中搜尋
http://10.10.110.125:9200/ods/_search?&pretty
3. 在索引ods和iteblog的所有類型中搜尋
http://10.10.110.125:9200/ods,iteblog/_search?&pretty
4. 在以0開頭或blog結尾的索引的所有類型中搜尋
http://10.10.110.125:9200/o,blog/_search?&pretty
5. 在索引"ods"的類型"jieshao"中搜尋
http://10.10.110.125:9200/ods/jieshao/_search?&pretty
6. 在索引 ods 和 iteblog 的類型為jieshao和iteblog中搜尋
http://10.10.110.125:9200/ods,iteblog/jieshao,iteblog/_search?&pretty
7. 在所有索引的 jieshao 和 iteblog 中搜尋
http://10.10.110.125:9200/_all/jieshao,iteblog/_search?&pretty
8. 在所有索引的 test_crm 的es_goods_order類型中搜尋sale_place=leying的文檔
http://10.10.110.125:9200/test_crm/es_goods_order/_search?q=sale_place:leying&pretty
作者:
丹江湖畔養蜂子的趙大爹
出處:http://www.cnblogs.com/honeybee/
關于作者:丹江湖畔養蜂子的趙大爹
本文版權歸作者和部落格園共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連結