使用ElasticSearch我们可以构建一个功能完备的搜索服务器.
这一切实现起来都很简单,本文将花五分钟向你介绍如何实现.
安装和运行Elasticsearch这篇文章的操作环境是Linux或者Mac,在安装ElasticSearch之前,确保你的系统上已经安装好JDK6或者以上版本.
wgethttps://download.
elastic.
co/elasticsearch/elasticsearch/elasticsearch-1.
7.
2.
tar.
gztar-zxvfelasticsearch-1.
7.
2.
tar.
gzcdelasticsearch-1.
7.
2bin/elasticsearch然后你将在终端看到如下输出:[2015-09-1415:32:52,278][INFO][node][BigMan]version[1.
7.
2],pid[10907],build[e43676b/2015-09-14T09:49:53Z][2015-09-1415:32:52,279][INFO][node][BigMan]initializing.
.
.
[2015-09-1415:32:52,376][INFO][plugins][BigMan]loaded[],sites[][2015-09-1415:32:52,426][INFO][env][BigMan]using[1]datapaths,mounts[[/(/dev/sdc1)]],netusable_space[8.
7gb],nettotal_space[219.
9gb],types[ext3]JavaHotSpot(TM)ServerVMwarning:Youhaveloadedlibrary/tmp/es/elasticsearch-1.
7.
2/lib/sigar/libsigar-x86-linux.
sowhichmighthavedisabledstackguard.
TheVMwilltrytofixthestackguardnow.
It'shighlyrecommendedthatyoufixthelibrarywith'execstack-c',orlinkitwith'-znoexecstack'.
[2015-09-1415:32:55,294][INFO][node][BigMan]initialized[2015-09-1415:32:55,294][INFO][node][BigMan]starting.
.
.
[2015-09-1415:32:55,411][INFO][transport][BigMan]bound_address{inet[/0:0:0:0:0:0:0:0:9300]},publish_address{inet[/192.
168.
43.
172:9300]}[2015-09-1415:32:55,428][INFO][discovery][BigMan]elasticsearch/VKL1HQmyT_KRtmTGznmQyg[2015-09-1415:32:59,210][INFO][cluster.
service][BigMan]new_master[BigMan][VKL1HQmyT_KRtmTGznmQyg][Happy][inet[/192.
168.
43.
172:9300]],reason:zen-disco-join(elected_as_master)[2015-09-1415:32:59,239][INFO][http][BigMan]bound_address{inet[/0:0:0:0:0:0:0:0:9200]},publish_address{inet[/192.
168.
43.
172:9200]}[2015-09-1415:32:59,239][INFO][node][BigMan]started1/5[2015-09-1415:32:59,284][INFO][gateway][BigMan]recovered[0]indicesintocluster_state现在你的系统上成功运行了Elasticsearch!
你可以在浏览器里面访问http://localhost:9200,这时候浏览器里面会返回以下内容:{"status":200,"name":"BigMan","cluster_name":"elasticsearch","version":{"number":"1.
7.
2","build_hash":"e43676b1385b8125d647f593f7202acbd816e8ec","build_timestamp":"2015-09-14T09:49:53Z","build_snapshot":false,"lucene_version":"4.
10.
4"},"tagline":"YouKnow,forSearch"}索引数据现在我们往ElasticSearch里面构建一些数据,我们假设有一个博客系统,里面有一些文章和评论相关的数据,现在将这些信息添加到ElasticSearch里面:curl-XPUT'http://localhost:9200/blog/user/dilbert'-d'{"name":"DilbertBrown"}'curl-XPUT'http://localhost:9200/blog/post/1'-d'{"user":"dilbert","postDate":"2011-12-15","body":"Searchishard.
Searchshouldbeeasy.
","title":"Onsearch"}'curl-XPUT'http://localhost:9200/blog/post/2'-d'{"user":"dilbert","postDate":"2011-12-12","body":"Distributionishard.
Distributionshouldbeeasy.
",2/5"title":"Ondistributedsearch"}'curl-XPUT'http://localhost:9200/blog/post/3'-d'{"user":"dilbert","postDate":"2011-12-10","body":"Loremipsumdolorsitamet,consectetueradipiscingelit,seddiamnonummynibheuismodtinciduntutlaoreetdoloremagnaaliquameratvolutpat","title":"Loremipsum"}'上面的每一步请求,你都会接受到一个响应,里面会证明你的请求成功,如下:{"ok":true,"_index":"blog","_type":"post","_id":"1","_version":1}现在我们来看看上面的请求是否正的成功了:curl-XGET'http://localhost:9200/blog/user/dilbertpretty=true'curl-XGET'http://localhost:9200/blog/post/1pretty=true'curl-XGET'http://localhost:9200/blog/post/2pretty=true'curl-XGET'http://localhost:9200/blog/post/3pretty=true'注意:往ElasticSearch里面添加数据主要有两种方式:通过HTTP发送Json数据;内置提供的客户端(Nativeclient).
搜索我们来看看我们是否可以检索我们刚刚通过搜索添加的文档,下面的例子是找出所有Dilbert作者的文章:curl'http://localhost:9200/blog/post/_searchq=user:dilbert&pretty=true'3/5上面的请求将会返回以下的Json结果:{"took":85,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":3,"max_score":1,"hits":[{"_index":"blog","_type":"post","_id":"1","_score":1,"_source":{"user":"dilbert","postDate":"2011-12-15","body":"Searchishard.
Searchshouldbeeasy.
","title":"Onsearch"}},{"_index":"blog","_type":"post","_id":"2","_score":0.
30685282,"_source":{"user":"dilbert","postDate":"2011-12-12","body":"Distributionishard.
Distributionshouldbeeasy.
","title":"Ondistributedsearch"}},{"_index":"blog","_type":"post","_id":"3","_score":0.
30685282,"_source":{"user":"dilbert","postDate":"2011-12-10",4/5"body":"Loremipsumdolorsitamet,consectetueradipiscingelit,seddiamnonummynibheuismodtinciduntutlaoreetdoloremagnaaliquameratvolutpat","title":"Loremipsum"}}]}}下面例子搜索标题不含search的文章curl'http://localhost:9200/blog/post/_searchq=-title:search&pretty=true'下面例子搜索标题包含search但是不包含distributed的文章:curl'http://localhost:9200/blog/post/_searchq=+title:search%20-title:distributed&pretty=true&fields=title'下面例子通过postDate字段搜索一定时间范围内的文章:curl-XGET'http://localhost:9200/blog/_searchpretty=true'-d'{"query":{"range":{"postDate":{"from":"2011-12-10","to":"2011-12-12"}}}}'好了,现在我们已经学习了ElasticSearch的一些基本的使用情况.
本博客文章除特别声明,全部都是原创!
原创文章版权归过往记忆大数据(过往记忆)所有,未经许可不得转载.
本文链接:【】()PoweredbyTCPDF(www.
tcpdf.
org)5/5
DMIT,最近动作频繁,前几天刚刚上架了日本lite版VPS,正在酝酿上线日本高级网络VPS,又差不多在同一时间推出了美国cn2 gia线路不限流量的美国云服务器,不过价格太过昂贵。丐版只有30M带宽,月付179.99 美元 !!目前美国云服务器已经有个4个套餐,分别是,Premium(cn2 gia线路)、Lite(普通直连)、Premium Secure(带高防的cn2 gia线路),Prem...
【双十二】兆赫云:全场vps季付六折优惠,低至50元/季,1H/1G/30M/20G数据盘/500G流量/洛杉矶联通9929商家简介:兆赫云是一家国人商家,成立2020年,主要业务是美西洛杉矶联通9929线路VPS,提供虚拟主机、VPS和独立服务器。VPS采用KVM虚拟架构,线路优质,延迟低,稳定性强。是不是觉得黑五折扣力度不够大?还在犹豫徘徊中?这次为了提前庆祝双十二,特价推出全场季付六折优惠。...
近日CloudCone发布了最新的补货消息,针对此前新年闪购年付便宜VPS云服务器计划方案进行了少量补货,KVM虚拟架构,美国洛杉矶CN2 GT线路,1Gbps带宽,最低3TB流量,仅需14美元/年,有需要国外便宜美国洛杉矶VPS云服务器的朋友可以尝试一下。CloudCone怎么样?CloudCone服务器好不好?CloudCone值不值得购买?CloudCone是一家成立于2017年的美国服务器...
博客系统为你推荐
软银亏损65亿美元美国国际集团(AIG)上一季度亏损617亿美元滴滴软银合资广州亚滴和滴滴有何关系?骁龙750g和765g哪个好高通骁龙845和骁龙835哪个好莫代尔和纯棉哪个好莫代尔和纯棉内裤哪个好?传奇类手游哪个好什么传奇手游还不错的 不烧钱 比较耐玩点网络机顶盒哪个好什么牌子的网络机顶盒最好视频软件哪个好编辑视频用什么软件最好qq空间登录器怎样直接登录QQ空间考生个人空间登录如何找回 自考考生个人空间的密码?360云盘共享群360云盘共享群怎么没有了
如何注销域名备案 万网域名证书查询 注册cn域名 smartvps 香港机房 全球付 sugarsync payoneer 好看qq空间 域名转向 百兆独享 域名评估 美国免费空间 双12 东莞服务器托管 服务器防火墙 防cc攻击 重庆联通服务器托管 第八届中美互联网论坛 阿里云宕机故障 更多