@hai046
2016-05-12T06:16:51.000000Z
字数 4995
阅读 957
solr
官方网站
http://lucene.apache.org/solr/#
java api接口
https://cwiki.apache.org/confluence/display/solr/Using+SolrJ
SpringDataSolr 源码
https://github.com/spring-projects/spring-data-solr
SpringDataSolr spring网站
http://projects.spring.io/spring-data-solr/#quick-start
solr中文资料相关
http://www.solr.cc/
bin/solr start -e cloud -z "zk.d.jiemoapp.com:2181"
配置2g内存,其中一个索引节点放在 /data/JiemoClouldSolr/jiemoAppSolr/node1/solr 端口是8983
/opt/solr/bin/solr start -c -p 8983 -s /data/JiemoClouldSolr/jiemoAppSolr/node1/solr -z "zk.d.jiemoapp.com:2181" -m 2g
/opt/solr/bin/solr start -c -p 9983 -s /data/JiemoClouldSolr/jiemoChatMsg/node1/solr -z "zk.d.jiemoapp.com:2181" -m 1g
/opt/solr/bin/solr start -c -p 9984 -s /data/JiemoClouldSolr/jiemoChatMsg/node2/solr -z "zk.d.jiemoapp.com:2181" -m 1g
一.Collections API
参考:https://cwiki.apache.org/confluence/display/solr/Collections+API
因为API比较多,我就不一一列举,只列出比较重要的几个
1.创建collection
官方示例:/admin/collections?action=CREATE&name=name&numShards=number&replicationFactor=number&maxShardsPerNode=number&createNodeSet=nodelist&collection.configName=configname
(1) 我的示例:
http://192.168.66.99:8080/solr/admin/collections?action=CREATE&name=test&numShards=2&replicationFactor=2&maxShardsPerNode=3
name指明collection名称
numShards指明分片数
replicationFactor指明副本数
maxShardsPerNode 每个节点最大分片数(默认为1)
(2)当我们想指定配置文件,索引目录时,可以加入如下参数
property.name=value string No Set core property name to value. See core.properties file contents.
可选参数如下:
key
Description
name
The name of the SolrCore. You'll use this name to reference the SolrCore when running commands with the CoreAdminHandler.
config
The configuration file name for a given core. The default is solrconfig.xml.
schema
The schema file name for a given core. The default is schema.xml
dataDir
Core's data directory as a path relative to the instanceDir, data by default.
configSet If set, the name of the configset to use to configure the core (see Config Sets).
properties
The name of the properties file for this core. The value can be an absolute pathname or a path relative to the value of instanceDir.
transient
If true, the core can be unloaded if Solr reaches the transientCacheSize. The default if not specified is false. Cores are unloaded in order of least recently used first.
loadOnStartup
If true, the default if it is not specified, the core will loaded when Solr starts.
coreNodeName
Added in Solr 4.2, this attributes allows naming a core. The name can then be used later if you need to replace a machine with a new one. By assigning the new machine the same coreNodeName as the old core, it will take over for the old SolrCore.
ulogDir
The absolute or relative directory for the update log for this core (SolrCloud)
shard
The shard to assign this core to (SolrCloud)
collection
The name of the collection this core is part of (SolrCloud)
roles
Future param for SolrCloud or a way for users to mark nodes for their own use.
(3)运行http://192.168.66.99:8080/solr/admin/collections?action=CREATE&name=test&numShards=2&replicationFactor=2&maxShardsPerNode=3&property.schema=schema2.xml&property.dataDir=/usr/local/data/solr
以上命令将会创建collection test,指定schema2.xml作为其schema配置文件,并指定/usr/local/data/solr为其数据存放目录
(注意如果指定相关配置文件,首先要向zookeeper中上传相关的配置,运行一下命令将schema2.xml上传到zookeeper
java -classpath .:/usr/local/solr/solrhome-1/lib/* org.apache.solr.cloud.ZkCLI -cmd upconfig -zkhost 127.0.0.1:1181,127.0.0.1:2181,127.0.0.1:3181 -confdir /usr/local/solr/solrhome-1/update/ -confname solr-conf
)
在我本机运行时出现错:
org.apache.solr.client.solrj.impl.HttpSolrServer$RemoteSolrException:Error CREATEing SolrCore 'test_shard1_replica1': Unable to create core: test_shard1_replica1 Caused by: Lock obtain timed out: NativeFSLock@/usr/local/data/solr/index/write.lock
这是因为3个节点都在我本机,我们将索引目录指定为同一个,这种创建方式默认的数据文件夹会重复,我们可以分别指定分片文件夹
2.删除collection
官方示例:/admin/collections?action=DELETE&name=collection
我的示例:http://192.168.66.99:8080/solr/admin/collections?action=DELETE&name=test
3.创建分片
官方示例:/admin/collections?action=CREATESHARD&shard=shardName&collection=name
/admin/collections?action=SPLITSHARD: split a shard into two new shards
我的示例:http://192.168.66.99:8080/solr/admin/collections?action=CREATESHARD&collection=test&shard=shard1&name=test_shard1_replica1&property.schema=schema2.xml&property.dataDir=/usr/local/data/solr/test_shard1_replica1
本人测试,如果collection是使用第1节方式创建的,使用这种方式进行创建分片时,无法正确执行,原因待研究
4.其他
/admin/collections?action=RELOAD: reload a collection
/admin/collections?action=SPLITSHARD: split a shard into two new shards
/admin/collections?action=CREATESHARD: create a new shard
/admin/collections?action=DELETESHARD: delete an inactive shard
/admin/collections?action=CREATEALIAS: create or modify an alias for a collection
/admin/collections?action=DELETEALIAS: delete an alias for a collection
/admin/collections?action=DELETEREPLICA: delete a replica of a shard
/admin/collections?action=ADDREPLICA: add a replica of a shard
/admin/collections?action=CLUSTERPROP: Add/edit/delete a cluster-wide property
/admin/collections?action=MIGRATE: Migrate documents to another collection
/admin/collections?action=ADDROLE: Add a specific role to a node in the cluster
/admin/collections?action=REMOVEROLE: Remove an assigned role
/admin/collections?action=OVERSEERSTATUS: Get status and statistics of the overseer
/admin/collections?action=CLUSTERSTATUS: Get cluster status
/admin/collections?action=REQUESTSTATUS: Get the status of a previous asynchronous request
/admin/collections?action=LIST: List all collections