Chinaunix首页 | 论坛 | 博客
  • 博客访问: 523273
  • 博文数量: 80
  • 博客积分: 1496
  • 博客等级: 上尉
  • 技术积分: 1292
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-18 11:24
个人简介

IT码农一个~

文章分类

全部博文(80)

文章存档

2020年(3)

2019年(7)

2017年(1)

2016年(2)

2015年(2)

2014年(26)

2013年(26)

2012年(2)

2011年(1)

2010年(1)

2008年(9)

我的朋友

分类: LINUX

2019-11-19 11:23:22


Solr Example
大纲 笔记Notes
  • 下载、安装
  • demo 练习
  • 总结

  • 下载、安装
  • cloud模式的启动、搜索、关闭
  • collection的新建、删除等
  • 总结

正文内容

前提要求,需要安装java-runtime, 也可以直接安装jdk
Debian10 : sudo apt install default-jdk 或者 指定版本:sudo apt install openjdk-11-jdk

官网:
下载:
直接使用的话,下载linux的bin版
直接tar zxvf solr-8.3.0.tgz , cd solr-8.3.0 
后续所有的命令可以在当前目录下, 执行 bin/solr  xxx 即可

帮助文档
gxl@deb10:~/solr/solr-8.3.0$ bin/solr -h

Usage: solr COMMAND OPTIONS
       where COMMAND is one of: start, stop, restart, status, healthcheck, create, create_core, create_collection, delete, version, zk, auth, assert, config, autoscaling, export

  Standalone server example (start Solr running in the background on port 8984):

    ./solr start -p 8984

  SolrCloud example (start Solr running in SolrCloud mode using localhost:2181 to connect to Zookeeper, with 1g max heap size and remote Java debug options enabled):

    ./solr start -c -m 1g -z localhost:2181 -a "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=1044"

  Omit '-z localhost:2181' from the above command if you have defined ZK_HOST in solr.in.sh.

Pass -help after any COMMAND to see command-specific usage information,
  such as:    ./solr start -help or ./solr stop -help

Demo使用

练习一:集群启动、collection创建、删除和常用搜索命令
./bin/solr start -e cloud (cloud模式启动,会启动多进程,通过zk管理集群) 如果需要单机模式 bin/solr start 即可

在提示 collection name的时候,需要把gettingstarted 替换为 techproducts, 不然后面无法导入数据
在提示 配置文件的时候,需要用 sample_techproducts_configs 替换 _default

启动成功后,即可访问, 如果是在其他机器访问,需要将localhost替换为 ip地址,比如  

导入测试数据:
bin/post -c techproducts example/exampledocs/*
也可以通过java命令,导入:
java -jar -Dc=techproducts -Dauto example\exampledocs\post.jar example\exampledocs\*

数据导入成功,就可以查询了,可以通过网页端,或者使用curl工具
 

或者
curl "

查询单一条件:
curl ""

限定字段查询:
curl "

按类别查询:
curl "

短语查询:   "CAS latency"
curl """

组合查询,使用+ (%2B)表示and,- 表示except
查询同时包含 electronics 和 music的产品
curl "

查询包含 electronics,但是不包含music的产品
curl ""

空间搜索:

collection的新建、删除:
bin/solr delete -c techproducts  

bin/solr create -c -s 2 -rf 2 #新建两个分区、两个备份的collection

solr集群的停止:
bin/solr stop -all



练习二:schema的建立、搜索
bin/solr create -c films -s 2 -rf 2  其中属性文件默认使用 _default

curl -X POST -H 'Content-type:application/json' --data-binary '{"add-field": {"name":"name", "type":"text_general", "multiValued":false, "stored":true}}'

创建catchall copyfield,慎用,生产环境可能会创建两重索引,比较耗时
curl -X POST -H 'Content-type:application/json' --data-binary '{"add-copy-field" : {"source":"*","dest":"_text_"}}'

导入文件,任意执行一种文件即可:
bin/post -c films example/films/films.json
bin/post -c films example/films/films.xml
bin/post -c films example/films/films.csv -params "f.genre.split=true&f.directed_by.split=true&f.genre.separator=|&f.directed_by.separator=|”

使用java原始命令:
java -jar -Dc=films -Dauto example\exampledocs\post.jar example\films\*.json
java -jar -Dc=films -Dauto example\exampledocs\post.jar example\films\*.xml
java -jar -Dc=films -Dparams=f.genre.split=true&f.directed_by.split=true&f.genre.separator=|&f.directed_by.separator=| -Dauto example\exampledocs\post.jar example\films\*.csv

查询:
Enter "comedy" in the q box and hit Execute Query again. You should see get 417 results

特征(facts) 查询:
To see facet counts from all documents (q=*:*): turn on faceting (facet=true), and specify the field to facet on via the facet.field parameter. If you only want facets, and no document contents, specify rows=0. The curl command below will return facet counts for the genre_str field:
curl "
If you wanted to control the number of items in a bucket, you could do something like this:
curl "

按区间特征查询:20年前 到 今年区间,间隔1年
curl ''
多轴特征查询:genre_str 和 directed_by_str 两个维度
curl ""
测试collection的删除:
bin/solr delete -c films

练习三:索引自己的数据
建立本地文档的collection
./bin/solr create -c localDocs -s 2 -rf 2

导入本地文档中的文件
./bin/post -c localDocs ~/Documents
如果文档更新,通过 bin/post 更新导入
Execute the following command to delete a specific document:
bin/post -c localDocs -d "SP2514N"
To delete all documents, you can use "delete-by-query" command like:
bin/post -c localDocs -d "*:*

删除所有example数据
bin/solr stop -all ; rm -Rf example/cloud/





总结Summary
启动、创建collection、导入数据、停止、删除
创建schema

阅读(1048) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~