`

solr 笔记

    博客分类:
  • solr
 
阅读更多

 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

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics