首页 文章 精选 留言 我的

精选列表

搜索[API网关],共10000篇文章
优秀的个人博客,低调大师

文档API

8.2.1.快速上手 文档通过 _index、_type、_id 元数据(metadata),确定 URL 唯一 GET /<_index>/<_type>/<_id> # curl -XPUT 'http://localhost:9200/website/profile/1' -d '{ "name" : "neo", "nickname" : "netkiller", "age" : "35", "message" : "Helloworld !!!" }' # curl -XGET 'http://localhost:9200/website/profile/1?pretty' { "_index" : "website", "_type" : "profile", "_id" : "1", "_version" : 1, "found" : true, "_source" : { "name" : "neo", "nickname" : "netkiller", "age" : "35", "message" : "Helloworld !!!" } } # curl -XPUT 'http://localhost:9200/website/blog/1?pretty' -d '{ > "title": "My first blog entry", > "text": "Just trying this out...", > "date": "2014/01/01" > }' { "_index" : "website", "_type" : "blog", "_id" : "1", "_version" : 1, "_shards" : { "total" : 2, "successful" : 1, "failed" : 0 }, "created" : true } 后面会详细讲解 PUT与GET的使用方法以及相关参数 8.2.2.写入 PUT/POST 通过 PUT 写入数据 [root@localhost ~]# curl -XPUT 'http://localhost:9200/twitter/tweet/1' -d '{ > "user" : "kimchy", > "post_date" : "2009-11-15T14:12:12", > "message" : "trying out Elasticsearch" > }' {"_index":"twitter","_type":"tweet","_id":"1","_version":1,"_shards":{"total":2,"successful":1,"failed":0},"created":true} 使用 UUID 替代 _id, 注意使用UUID 必须使用 POST方式提交,不能使用 PUT。 curl -XPOST 'http://localhost:9200/website/news/?pretty' -d '{ "title": "My first news entry", "text": "Just trying this out..." }' { "_index" : "website", "_type" : "news1", "_id" : "AVY0RJrvJRTrBLpmYzBH", "_version" : 1, "_shards" : { "total" : 2, "successful" : 1, "failed" : 0 }, "created" : true } curl -XGET 'http://localhost:9200/website/news/AVY0RJrvJRTrBLpmYzBH?pretty' 提交后会输出 "_id" : "AVY0RJrvJRTrBLpmYzBH",查询时将此放到放到URL中即可。 8.2.3.获取 GET 通过 GET 读取数据 [root@localhost ~]# curl -XGET 'http://localhost:9200/twitter/tweet/1' {"_index":"twitter","_type":"tweet","_id":"1","_version":1,"found":true,"_source":{ "user" : "kimchy", "post_date" : "2009-11-15T14:12:12", "message" : "trying out Elasticsearch" }} 8.2.3.1._source 只返回 _source 数据,去掉元数据 # curl -XGET 'http://localhost:9200/website/news1/AVY0Q4SqdtH0Up0t-WB2/_source?pretty' { "title" : "My first news entry", "text" : "Just trying this out..." } 选择字段 _source=title,超过一个字段使用逗号分隔_source=title,text。 # curl -XGET 'http://localhost:9200/website/news1/AVY0Q4SqdtH0Up0t-WB2?_source=title&pretty' { "_index" : "website", "_type" : "news1", "_id" : "AVY0Q4SqdtH0Up0t-WB2", "_version" : 1, "found" : true, "_source" : { "title" : "My first news entry" } } # curl -XGET 'http://localhost:9200/website/news1/AVY0Q4SqdtH0Up0t-WB2?_source=title,text&pretty' { "_index" : "website", "_type" : "news1", "_id" : "AVY0Q4SqdtH0Up0t-WB2", "_version" : 1, "found" : true, "_source" : { "text" : "Just trying this out...", "title" : "My first news entry" } } 8.2.4.检查记录是否存在 [root@localhost elasticsearch]# curl -i -XHEAD http://localhost:9200/website/blog/1 HTTP/1.1 200 OK Content-Type: text/plain; charset=UTF-8 Content-Length: 0 [root@localhost elasticsearch]# curl -i -XHEAD http://localhost:9200/website/blog/100 HTTP/1.1 404 Not Found Content-Type: text/plain; charset=UTF-8 Content-Length: 0 HTTP/1.1 200 OK 表示已经找到你要的数据 HTTP/1.1 404 Not Found 表示数据不存在 8.2.5.删除 Delete 删除 _index curl -XDELETE http://localhost:9200/information/?pretty 删除 _mapping curl -XDELETE http://localhost:9200/information/news/_mapping?pretty 删除对象 curl -XDELETE http://localhost:9200/information/news/1?pretty 8.2.6.参数 8.2.6.1.pretty 格式化 json # curl -XGET 'http://localhost:9200/twitter/tweet/1?pretty' { "_index" : "twitter", "_type" : "tweet", "_id" : "1", "_version" : 1, "found" : true, "_source" : { "user" : "kimchy", "post_date" : "2009-11-15T14:12:12", "message" : "trying out Elasticsearch" } } 原文出处:Netkiller 系列 手札 本文作者:陈景峯 转载请与作者联系,同时请务必标明文章原始出处和作者信息及本声明。

优秀的个人博客,低调大师

Elasticsearch常用操作API

1. 查询所有的索引 1 2 3 4 [root@Server01cx] #curl'10.0.0.5:9200/_cat/indices?v' healthstatusindexprirepdocs.countdocs.deletedstore.sizepri.store.size yellow open customer51206.6kb6.6kb yellow open bank5110000442.1kb442.1kb 2. 查询bank表中的所有数据 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 [root@Server01cx] #curl'10.0.0.5:9200/bank/_search?q=*&pretty' { "took" :41, "timed_out" : false , "_shards" :{ "total" :5, "successful" :5, "failed" :0 }, "hits" :{ "total" :1000, "max_score" :1.0, "hits" :[{ "_index" : "bank" , "_type" : "account" , "_id" : "25" , "_score" :1.0, "_source" :{ "account_number" :25, "balance" :40540, "firstname" : "Virginia" , "lastname" : "Ayala" , "age" :39, "gender" : "F" , "address" : "171PutnamAvenue" , "employer" : "Filodyne" , "email" : "virginiaayala@filodyne.com" , "city" : "Nicholson" , "state" : "PA" } },{ "_index" : "bank" , "_type" : "account" , "_id" : "44" , "_score" :1.0, "_source" :{ "account_number" :44, "balance" :34487, "firstname" : "Aurelia" , "lastname" : "Harding" , "age" :37, "gender" : "M" , "address" : "502BaycliffTerrace" , "employer" : "Orbalix" , "email" : "aureliaharding@orbalix.com" , "city" : "Yardville" , "state" : "DE" } },{ "_index" : "bank" , "_type" : "account" , "_id" : "99" , "_score" :1.0, "_source" :{ "account_number" :99, "balance" :47159, "firstname" : "Ratliff" , "lastname" : "Heath" , "age" :39, "gender" : "F" , "address" : "806RockwellPlace" , "employer" : "Zappix" , "email" : "ratliffheath@zappix.com" , "city" : "Shaft" , "state" : "ND" } },{ "_index" : "bank" , "_type" : "account" , "_id" : "119" , "_score" :1.0, "_source" :{ "account_number" :119, "balance" :49222, "firstname" : "Laverne" , "lastname" : "Johnson" , "age" :28, "gender" : "F" , "address" : "302HowardPlace" , "employer" : "Senmei" , "email" : "lavernejohnson@senmei.com" , "city" : "Herlong" , "state" : "DC" } },{ "_index" : "bank" , "_type" : "account" , "_id" : "126" , "_score" :1.0, "_source" :{ "account_number" :126, "balance" :3607, "firstname" : "Effie" , "lastname" : "Gates" , "age" :39, "gender" : "F" , "address" : "620NationalDrive" , "employer" : "Digitalus" , "email" : "effiegates@digitalus.com" , "city" : "Blodgett" , "state" : "MD" } },{ "_index" : "bank" , "_type" : "account" , "_id" : "145" , "_score" :1.0, "_source" :{ "account_number" :145, "balance" :47406, "firstname" : "Rowena" , "lastname" : "Wilkinson" , "age" :32, "gender" : "M" , "address" : "891EltonStreet" , "employer" : "Asimiline" , "email" : "rowenawilkinson@asimiline.com" , "city" : "Ripley" , "state" : "NH" } },{ "_index" : "bank" , "_type" : "account" , "_id" : "183" , "_score" :1.0, "_source" :{ "account_number" :183, "balance" :14223, "firstname" : "Hudson" , "lastname" : "English" , "age" :26, "gender" : "F" , "address" : "823HerkimerPlace" , "employer" : "Xinware" , "email" : "hudsonenglish@xinware.com" , "city" : "Robbins" , "state" : "ND" } },{ "_index" : "bank" , "_type" : "account" , "_id" : "190" , "_score" :1.0, "_source" :{ "account_number" :190, "balance" :3150, "firstname" : "Blake" , "lastname" : "Davidson" , "age" :30, "gender" : "F" , "address" : "636DiamondStreet" , "employer" : "Quantasis" , "email" : "blakedavidson@quantasis.com" , "city" : "Crumpler" , "state" : "KY" } },{ "_index" : "bank" , "_type" : "account" , "_id" : "208" , "_score" :1.0, "_source" :{ "account_number" :208, "balance" :40760, "firstname" : "Garcia" , "lastname" : "Hess" , "age" :26, "gender" : "F" , "address" : "810NostrandAvenue" , "employer" : "Quiltigen" , "email" : "garciahess@quiltigen.com" , "city" : "Brooktrails" , "state" : "GA" } },{ "_index" : "bank" , "_type" : "account" , "_id" : "222" , "_score" :1.0, "_source" :{ "account_number" :222, "balance" :14764, "firstname" : "Rachelle" , "lastname" : "Rice" , "age" :36, "gender" : "M" , "address" : "333NarrowsAvenue" , "employer" : "Enaut" , "email" : "rachellerice@enaut.com" , "city" : "Wright" , "state" : "AZ" } }] } } took– Elasticsearch执行查询的毫秒响应时间 timed_out– 是否超时 _shards– 查询过的分片,包含成功的分片和失败的分片 hits– 搜索结果 hits.total– 符合搜索结果的记录数 hits.hits– 默认显示前10条搜索结果 _scoreandmax_score- ignore these fields for now 3. 另外一种查询全部结果的方法 1 2 3 4 curl-XPOST '10.0.0.5:9200/bank/_search?pretty' -d' { "query" :{ "match_all" :{}} }' 4. 分页排序的检索例子 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 [root@Server01cx] #curl-XPOST'10.0.0.5:9200/bank/_search?pretty'-d' { "query" :{ "match_all" :{}}, "from" :10, "size" :3, "sort" :{ "balance" :{ "order" : "desc" }} }' { "took" :8, "timed_out" : false , "_shards" :{ "total" :5, "successful" :5, "failed" :0 }, "hits" :{ "total" :1000, "max_score" :null, "hits" :[{ "_index" : "bank" , "_type" : "account" , "_id" : "255" , "_score" :null, "_source" :{ "account_number" :255, "balance" :49339, "firstname" : "Iva" , "lastname" : "Rivers" , "age" :38, "gender" : "M" , "address" : "470RostPlace" , "employer" : "Mantrix" , "email" : "ivarivers@mantrix.com" , "city" : "Disautel" , "state" : "MD" }, "sort" :[49339] },{ "_index" : "bank" , "_type" : "account" , "_id" : "524" , "_score" :null, "_source" :{ "account_number" :524, "balance" :49334, "firstname" : "Salas" , "lastname" : "Farley" , "age" :30, "gender" : "F" , "address" : "499TrucklemansLane" , "employer" : "Xumonk" , "email" : "salasfarley@xumonk.com" , "city" : "Noxen" , "state" : "AL" }, "sort" :[49334] },{ "_index" : "bank" , "_type" : "account" , "_id" : "751" , "_score" :null, "_source" :{ "account_number" :751, "balance" :49252, "firstname" : "Patrick" , "lastname" : "Osborne" , "age" :23, "gender" : "M" , "address" : "915ProspectAvenue" , "employer" : "Gynko" , "email" : "patrickosborne@gynko.com" , "city" : "Takilma" , "state" : "MO" }, "sort" :[49252] }] } } 5. 添加文档,如果id存在则更新文档 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 [root@Server01data] #curl-XPUT'10.0.0.5:9200/customer/external/1?pretty'-d' >{ "name" : "JohnDoe" }' { "_index" : "customer" , "_type" : "external" , "_id" : "1" , "_version" :1, "_shards" :{ "total" :2, "successful" :1, "failed" :0 }, "created" : true } [root@Server01data] #curl-XPUT'10.0.0.5:9200/customer/external/1?pretty'-d' { "name" : "JaneDoe" }' { "_index" : "customer" , "_type" : "external" , "_id" : "1" , "_version" :2, "_shards" :{ "total" :2, "successful" :1, "failed" :0 }, "created" : false } 6. 不指定Id时创建文档,可以发现自动生成一个随机Id 1 2 3 4 5 6 7 8 9 10 11 12 13 [root@Server01data] #curl-XPOST'10.0.0.5:9200/customer/external?pretty'-d'{"name":"JaneDoe"}' { "_index" : "customer" , "_type" : "external" , "_id" : "AVTh53KZ4Pj5B2ZQ2voK" , "_version" :1, "_shards" :{ "total" :2, "successful" :1, "failed" :0 }, "created" : true } 7. 修改文档 1 2 3 4 5 6 7 8 9 10 11 12 [root@Server01data] #curl-XPOST'10.0.0.5:9200/customer/external/2/_update?pretty'-d'{"doc":{"name":"favouriteboy","age":18}}' { "_index" : "customer" , "_type" : "external" , "_id" : "2" , "_version" :3, "_shards" :{ "total" :2, "successful" :1, "failed" :0 } } 8. 在开启javascript后,可以使用JS脚本更新文档 1 [root@Server01data] #curl-XPOST'10.0.0.5:9200/customer/external/2/_update?pretty'-d'{"script":"ctx._source.age+=5"}' 9. 删除文档 1 2 3 4 5 6 7 8 9 10 11 12 13 [root@Server01data] #curl-XDELETE'10.0.0.5:9200/customer/external/1?pretty' { "found" : true , "_index" : "customer" , "_type" : "external" , "_id" : "1" , "_version" :4, "_shards" :{ "total" :2, "successful" :1, "failed" :0 } } 10. 批量更新文档 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 [root@Server01data] #curl-XPOST'10.0.0.5:9200/customer/external/_bulk?pretty'-d' { "index" :{ "_id" : "1" }} { "name" : "JohnDoe" } { "index" :{ "_id" : "2" }} { "name" : "JaneDoe" }' { "took" :33, "errors" : false , "items" :[{ "index" :{ "_index" : "customer" , "_type" : "external" , "_id" : "1" , "_version" :3, "_shards" :{ "total" :2, "successful" :1, "failed" :0 }, "status" :200 } }] } [root@Server01data] #curl-XPOST'10.0.0.5:9200/customer/external/_bulk?pretty'-d' >{ "update" :{ "_id" : "1" }} >{ "doc" :{ "name" : "JohnDoebecomesJaneDoe" }} >{ "delete" :{ "_id" : "2" }} >' { "took" :34, "errors" : false , "items" :[{ "update" :{ "_index" : "customer" , "_type" : "external" , "_id" : "1" , "_version" :4, "_shards" :{ "total" :2, "successful" :1, "failed" :0 }, "status" :200 } },{ "delete" :{ "_index" : "customer" , "_type" : "external" , "_id" : "2" , "_version" :5, "_shards" :{ "total" :2, "successful" :1, "failed" :0 }, "status" :200, "found" : true } }] } 本文转自 genuinecx 51CTO博客,原文链接:http://blog.51cto.com/favccxx/1793613,如需转载请自行联系原作者

优秀的个人博客,低调大师

基于PLC智能网关的智能物料分拣物联网系统

随着电子商务与智能制造的快速发展,物流及生产车间对物料分拣的效率与准确性提出了更高要求。传统的人工分拣方式劳动强度大、错误率高,已难以满足连续大批量的生产需求。某大型物流分拣中心的核心工序——物料自动分拣,长期依赖现场人员监控设备运行、人工统计分拣数量。一旦设备异常故障未能及时发现,将导致物料错分、堆积甚至设备卡顿,不仅工作量大、效率低下,也制约了企业向数字化、智能化方向转型。

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册