使用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
香港服务器多少钱一个月?香港服务器租用配置价格一个月多少,现在很多中小型企业在建站时都会租用香港服务器,租用香港服务器可以使网站访问更流畅、稳定性更好,安全性会更高等等。香港服务器的租用和其他地区的服务器租用配置元素都是一样的,那么为什么香港服务器那么受欢迎呢,香港云服务器最便宜价格多少钱一个月呢?阿里云轻量应用服务器最便宜的是1核1G峰值带宽30Mbps,24元/月,288元/年。不过我们一般选...
RAKsmart发布了9月份优惠促销活动,从9月1日~9月30日期间,爆款美国服务器每日限量抢购最低$30.62-$46/月起,洛杉矶/圣何塞/香港/日本站群大量补货特价销售,美国1-10Gbps大带宽不限流量服务器低价热卖等。RAKsmart是一家华人运营的国外主机商,提供的产品包括独立服务器租用和VPS等,可选数据中心包括美国加州圣何塞、洛杉矶、中国香港、韩国、日本、荷兰等国家和地区数据中心(...
今天有网友提到自己在Linux服务器中安装VNC桌面的时候安装都没有问题,但是在登录远程的时候居然有出现灰色界面,有三行代码提示"Accept clipboard from viewers,Send clipboard to viewers,Send primary selection to viewers"。即便我们重新登录也不行,这个到底如何解决呢?这里找几个可以解决的可能办法,我们多多尝试。...
博客系统为你推荐
桌面背景图片淡雅电脑自带的桌面背景图片原来合适现在不合适了怎么办集成显卡和独立显卡哪个好独立显卡和集成显卡区别??电脑管家和360哪个好360和电脑管家哪个好啊浏览器哪个好用哪个浏览器比较好绝地求生加速器哪个好绝地求生的加速器哪个好用?qq空间登录网页版求这张图的原图,是QQ空间最近网页版登录界面的背景空间登录器用什么登录器可以登录QQ(除了QQ登录器)网通dns服务器地址中国联通的默认DNS是多少360云盘关闭360云盘,关闭了吗,还能用吗,推荐一个其他云盘360云盘共享群360云盘共享群以后还有吗
免费cn域名注册 网站虚拟主机空间 网站备案域名查询 免费域名解析 主机测评 photonvps 59.99美元 外国空间 evssl证书 dropbox网盘 申请个人网站 jsp空间 域名转接 adroit 台湾谷歌 厦门电信 美国盐湖城 免费的域名 秒杀品 贵阳电信测速 更多