五分钟了解Elasticsearch

博客系统  时间:2021-01-30  阅读:()
使用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

VoLLcloud7折月付$3,香港CMI云服务器原生IP解锁,香港VoLLcloud

vollcloud怎么样?vollcloud LLC创立于2020年,是一家以互联网基础业务服务为主的 技术型企业,运营全球数据中心业务。VoLLcloud LLC针对新老用户推出全场年付产品7折促销优惠,共30个,机会难得,所有产品支持3日内无条件退款,同时提供产品免费体验。目前所有产品中,“镇店之宝”产品性价比高,适用大部分用户基础应用,卖的也是最好,同时,在这里感谢新老用户的支持和信任,我们...

炭云188元/年,上海CN2 VPS/2核/384MB内存/8GB空间/800GB流量/77Mbps端口/共享IP

炭云怎么样?炭云(之前的碳云),国人商家,正规公司(哈尔滨桓林信息技术有限公司),主机之家测评介绍过多次。现在上海CN2共享IP的VPS有一款特价,上海cn2 vps,2核/384MB内存/8GB空间/800GB流量/77Mbps端口/共享IP/Hyper-v,188元/年,特别适合电信网络。有需要的可以关注一下。点击进入:炭云官方网站地址炭云vps套餐:套餐cpu内存硬盘流量/带宽ip价格购买上...

Ftech:越南vps,2核/2G/20G SSD/1Gbps不限流量/可安装Windows系统,$12.5月

ftech怎么样?ftech是一家越南本土的主机商,成立于2011年,比较低调,国内知道的人比较少。FTECH.VN以极低的成本提供高质量服务的领先提供商之一。主营虚拟主机、VPS、独立服务器、域名等传统的IDC业务,数据中心分布在河内和胡志明市。其中,VPS提供1G的共享带宽,且不限流量,还可以安装Windows server2003/2008的系统。Ftech支持信用卡、Paypal等付款,但...

博客系统为你推荐
等额本息等额本金哪个好等额本息与等额本金哪个划算?炒股软件哪个好炒股软件真的那么好用吗?电陶炉和电磁炉哪个好电陶炉和电磁炉哪个好百度空间登录百度空间怎么登陆飞信空间登录怎样在网上登陆飞信qq网盘在哪里QQ网盘在哪里首选dns服务器地址什么是首选DNS服务器和备用DNS服务器?dns服务器有什么用DNS服务器有什么做用360云盘36t360 wifi随身 10t 有限制吗360云盘转存百度云盘怎样将360云盘中文件快速转存到百度云盘
虚拟主机排名 申请域名 域名备案只选云聚达 泛域名解析 3322免费域名 cn域名个人注册 krypt qq云存储 高防dns 香港机房托管 名片模板psd 国内加速器 qq数据库 e蜗 日本bb瘦 gspeed 服务器维护方案 域名评估 微软服务器操作系统 idc查询 更多