- 添加一个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