使用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
rangcloud怎么样?rangcloud是去年年初开办的国人商家,RangCloud是一家以销售NAT起步,后续逐渐开始拓展到VPS及云主机业务,目前有中国香港、美国西雅图、韩国NAT、广州移动、江门移动、镇江BGP、山东联通、山东BGP等机房。目前,RangCloud提供香港CN2线路云服务器,电信走CN2、联通移动直连,云主机采用PCle固态硬盘,19.8元/月起,支持建站使用;美国高防云...
今天有网友提到自己在Linux服务器中安装VNC桌面的时候安装都没有问题,但是在登录远程的时候居然有出现灰色界面,有三行代码提示"Accept clipboard from viewers,Send clipboard to viewers,Send primary selection to viewers"。即便我们重新登录也不行,这个到底如何解决呢?这里找几个可以解决的可能办法,我们多多尝试。...
易探云产品限时秒杀&QQ音乐典藏活动正在进行中!购买易探云香港/美国云服务器送QQ音乐绿钻豪华版1年,价值180元,性价比超级高。目前,有四大核心福利产品推荐:福利一、香港云服务器1核1G2M,仅218元/年起(香港CN2线路,全球50ms以内);福利二、美国20G高防云服务器1核1G5M,仅336元/年起(美国BGP线路,自带20G防御);福利三、2G虚拟主机低至58.8元/年(更有免费...
博客系统为你推荐
麒麟990和骁龙865哪个好海思麒麟990和骁龙710哪个好?小说软件哪个好用免费现在看小说用什么软件好?二手车网站哪个好想买台二手车,哪个二手车网站靠谱无纺布和熔喷布口罩哪个好医用 口罩里面是无纺布好还是过滤纸好核芯显卡与独立显卡哪个好核芯显卡与独立显卡哪个好红茶和绿茶哪个好红茶和绿茶哪个比较好?电动牙刷哪个好什么品牌的电动牙刷比较好?美国国际集团深圳500强企业都有哪些?如何增加百度收录如何快速提高百度收录量上海dns服务器地址上海浦东新区dns是多少
优key 腾讯云数据库 xfce tightvnc 免费静态空间 租空间 微信收钱 isp服务商 东莞服务器 中国电信测速器 网站加速软件 美国凤凰城 smtp服务器地址 中国电信测速网站 个人免费邮箱 德讯 免费网络 ledlamp 阿里云邮箱登陆地址 主机返佣 更多