solr学习笔记-入门

solr学习笔记
1、安装前准备

solr依赖java 8 运行环境,所以我们先安装java。如果没有java环境无法启动solr服务,并且会看到如下提示:

[root@localhost solr-6.1.0]# ./bin/solr start -e cloud -noprompt /*运行solr服务*/
Java not found, or an error was encountered when running java.
A working Java 8 is required to run Solr!
Please install Java 8 or fix JAVA_HOME before running this script.
Command that we tried: 'java -version'
[root@localhost ~]# java -version /*检测是否已安装java*/
[root@localhost ~]#  yum install -y java /*安装java*/

2、下载&安装&启动&停止
1.1、下载&安装:下载安装包,然后直接解压到指定目录即可。

[root@localhost ~]# wget http://ftp.meisei-u.ac.jp/mirror/apache/dist/lucene/solr/6.1.0/solr-6.1.0.tgz
[root@localhost ~]# tar zxvf solr-6.1.0.tgz -C /usr/local/
[root@localhost ~]# cd /usr/local/solr-6.1.0
[root@localhost solr-6.1.0]# ls
bin  CHANGES.txt  contrib  dist  docs  example  licenses  LICENSE.txt  LUCENE_CHANGES.txt  NOTICE.txt  README.txt  server
[root@localhost solr-6.1.0]# ./bin/solr -help /*查看solr命令帮助*/
[root@localhost solr-6.1.0]# ./bin/solr status /*查看solr服务启动状态*/

1.2、启动solr服务
[root@localhost solr-6.1.0]# ./bin/solr start -e cloud -noprompt /*启动solr服务*/
Welcome to the SolrCloud example!
Starting up 2 Solr nodes for your example SolrCloud cluster.
/*省略中间部分*/
SolrCloud example running, please visit: http://localhost:8983/solr /*浏览器打开这个url可以看到solr的运行情况*/
[root@localhost solr-6.1.0]# ps aux | grep solr /*可以看到solr服务进程*/
[root@localhost solr-6.1.0]# ./bin/solr start -help /*查看启动命令帮助*/

1.3、停止solr服务
[root@localhost solr-6.1.0]# ./bin/solr stop -all
[root@localhost solr-6.1.0]# ./bin/solr start -help /*查看停止命令帮助*/

3、生成索引数据
solr使用./bin/post命令生成索引数据。支持多种生成方式:
3.1、指定文件生成索引数据,支持格式:xml,json,jsonl,csv,pdf,doc,docx,ppt,pptx,xls,xlsx,odt,odp,ods,ott,otp,ots,rtf,htm,html,txt,log
[root@localhost solr-6.1.0]# ./bin/post -c gettingstarted filename.json

3.2、指定目录生成索引数据
[root@localhost solr-6.1.0]# ./bin/post -c gettingstarted ~/docdir

3.3、网络爬虫
[root@localhost solr-6.1.0]# ./bin/post -c gettingstarted http://lucene.apache.org/solr -recursive 1 -delay 1

3.4、标准输入/输出管道
[root@localhost solr-6.1.0]# echo '{commit: {}}' | ./bin/post -c gettingstarted -type application/json -out yes -d

3.5、字符串
[root@localhost solr-6.1.0]# ./bin/post -c gettingstarted -type text/csv -out yes -d $'id,value\n1,0.47'

注:文件内容格式可以参考solr安装目录内的/usr/local/solr-6.1.0/example/exampledocs/*下文件。

4、删除索引数据
我们可以指定要删除记录的主键值来删除指定记录,或者在文档中定义指定记录的值批量删除
4.1、删除主键ID值为SP2514N的记录,-d参数是可以是其他solr支持的格式或文件
[root@localhost solr-6.1.0]# ./bin/post -c gettingstarted -d "<delete><id>SP2514N</id></delete>"

5、搜索
Solr支持多种搜索渠道,如:REST clients, cURL, wget, Chrome POSTMAN等等.理论上支持所有语言。
5.1、CURL方式:
[root@localhost solr-6.1.0]# curl "http://localhost:8983/solr/gettingstarted/select?q=*:*&wt=json&indent=true"

5.2、搜索API常用参数说明
5.2.1、参数[q=keyword|field:value|keyword1+keyword2|keyword1+-keyword2]:搜索关键字|包含value的字段field|同时包含keyword1和keyword2|包含keyword1,但不包含keyword2。
5.2.2、参数[wt=json]:结果返回格式:json、xml、python、ruby、php、csv等。
5.2.3、参数[start=0]:分页偏移量,即从第几条开始。
5.2.4、参数[rows=10]:每页数量,默认10。
5.2.5、参数[fl=id[,field2,field3,...]]:结果只返回指定的字段,多个用“,”隔开。
5.2.6、参数[indent=false|true]:返回结果个否格式化(缩进)。
5.2.7、参数[fq=field:value]:过滤结果
5.2.8、参数[facet=true|false|on|off]:开始/关闭分组,统计分组数量
5.2.8、参数[facet.field=field]:以field字段分组统计
更多参数说明:https://cwiki.apache.org/confluence/display/solr/Query+Syntax+and+Parsing

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值