1.集群模式启动
./solr -c -z 127.0.0.1:2181 -p 9001 -t /data/solr/solr-cloud-data/node1 -force
-c 集群模式
-z zookeeper地址
-p 端口号
-t 指定数据目录
-force 以root方式启动时,需要使用该参数
2. 停止solr
./solr stop -p 9001
-p 端口号
3. solrconfig.xml
.配置schema为手动修改模式(经典模式)
修改 solrconfig.xml :
a.增加:<schemaFactory class="ClassicIndexSchemaFactory"/>
(手动修改 schema.xml ,而不是用接口api修改schema配置。 )
{api方式:默认方式:ManagedIndexSchemaFactory }
b. 自动创建字段设为false
<!-- The update.autoCreateFields property can be turned to false to disable schemaless mode -->
<updateRequestProcessorChain name="add-unknown-fields-to-the-schema" default="${update.autoCreateFields:true}"
processor="uuid,remove-blank,field-name-mutating,parse-boolean,parse-long,parse-double,parse-date,add-schema-fields">
<processor class="solr.LogUpdateProcessorFactory"/>
<processor class="solr.DistributedUpdateProcessorFactory"/>
<processor class="solr.RunUpdateProcessorFactory"/>
</updateRequestProcessorChain>
修改成:defalut = false
. 指定软提交时间:
<autoSoftCommit>
<maxTime>5000</maxTime>
</autoSoftCommit>
4. 配置字段及类型 (schema.xml)
${solr_home}/server/solr/configsets/_default 目录copy managed_schema to schema.xml .
在schema.xml上增加字段。
动态字段:如果数据随机增加字段,可以使用动态字段如:
<dynamicField name="*_i" type="pint" indexed="true" stored="true"/>
<dynamicField name="*_is" type="pints" indexed="true" stored="true"/> <dynamicField name="*_s" type="string" indexed="true" stored="true" /> <dynamicField name="*_ss" type="strings" indexed="true" stored="true"/> <dynamicField name="*_l" type="plong" indexed="true" stored="true"/> <dynamicField name="*_ls" type="plongs" indexed="true" stored="true"/> <dynamicField name="*_t" type="text_general" indexed="true" stored="true" multiValued="false"/> <dynamicField name="*_txt" type="text_general" indexed="true" stored="true"/> <dynamicField name="*_b" type="boolean" indexed="true" stored="true"/> <dynamicField name="*_bs" type="booleans" indexed="true" stored="true"/> <dynamicField name="*_f" type="pfloat" indexed="true" stored="true"/> <dynamicField name="*_fs" type="pfloats" indexed="true" stored="true"/> <dynamicField name="*_d" type="pdouble" indexed="true" stored="true"/> <dynamicField name="*_ds" type="pdoubles" indexed="true" stored="true"/>
要求字段名匹配上面的name。
另外:如果字段名,不是按_i、_s等结尾的规则,也可以使用:
<dynamicField name="*" type="string" indexed="true" stored="true" />
结果是所有字段名未匹配的字段,都转换为string类型存储了。
多值字段:
如:"hobby":["玩","吃","喝"]
<field name="hobby" type="string" indexed="false" stored="true" required="false" multiValued="true"/>
忽略未定义的字段:
<dynamicField name="*" type="ignored" multiValued="true"/> <fieldType name="ignored" stored="false" indexed="false" multiValued="true" class="solr.StrField" />
5.上传配置文件到zk:
./solr zk upconfig -z 127.0.0.1:2181 -n mycollection -d /opt/mycollection_conf
-z zookeeper地址
-n 新建的配置名称,之后创建collection 会关联这个名称而找到配置文件。
-d 指定配置文件的目录,配置文件如:
schema.xml, protwords.txt, params.json, solrconfig.xml, synonyms.txt, stopwords.txt 等
这些文件可以从默认配置中copy 过来,再修改成想要的。
默认配置路径:${solr_home}/server/solr/configsets/_default
6.创建collection:
6.1 以implicit模式创建
http://localhost:9001/solr/admin/collections?action=CREATE&name=mycollection&router.name=implicit&numShards=2
&shards=shard0,shard1&replicationFactor=2&
collection.configName=mycollection&router.field=_router_
name :collection 名称
router.field:路由字段名,(schema.xml中配置的字段)
numShards: shard 个数
shards:shard 名称(逗号分隔),名称数与shard个数相同。
replicationFactor:副本个数
router.name:implicit
以implicit方式创建,写入时,数据中需要有router.field配置的字段,该字段的值=shards中配置的名称,就对应到哪个 shard上。
6.2 以composite 方式创建:
http://localhost:8983/solr/admin/collections?action=create&name=mycollection
&router.name=compositeId&numShards=5&replicationFactor=2
&collection.configName=mycollection
name :collection 名称
router.field:路由字段名,(schema.xml中配置的字段)
numShards: shard 个数
replicationFactor:副本个数
router.name:compositeId
以compositeId方式创建,写入时,solr根据文档主键值,取hash,确定数据写入到哪个shard的,每个shard
保存固定hash范围的数据。
7.删除collections:
http://localhost:8983/solr/admin/collections?action=DELETE&name=mycollection
8.查询:
http://localhost:9001/solr/mycollection/select?q=_router_:shard0
相关推荐
solr笔记solr笔记
Solr笔记,Solr笔记,Solr笔记,Solr笔记,Solr笔记,Solr笔记,Solr笔记,Solr笔记,Solr笔记,Solr笔记,
solr笔记教案solr笔记教案
activemq,dubbo,linux,redis,shiro,solr笔记整理+视频资源
solr facet 笔记
搜索引擎
集合了activemq,dubbo,Linux,Redis,shiro, solr,各种经典面试问题,还有各方面重点笔记整合。
lucene和solr笔记
Solr学习笔记
solr学习的关键命令使用说明,包括插入命令与查询命令
solr 学习必备,多看看吧!solr学习笔记,对于初学者不错的!来分享
1.下载solr7.5.tar,拷贝到CentOS解压 2.启动solr 3.开启该端口防火墙 4.控制界面访问 5.创建一个核心(又名索引)(此处测试名称:core1) 6.配置数据库读取信息:DataImportHandler 7.重启solr在core1导入数据库...
solr_学习笔记_v1.1
原始数据,用来建立索引 博文链接:https://kylinsoong.iteye.com/blog/712704