我最近开始探索SolrCloud并正在尝试索引 使用CloudSolrServer客户端的文档。我看到的问题是,如果我不这样做 在CloudSolrServer对象上触发显式提交,文档不是 获得索引。这是我的代码片段:
code> CloudSolrServer server = new CloudSolrServer("localhost:2181"); server.setDefaultCollection("collection1"); SolrInputDocument doc = new SolrInputDocument(); doc.addField("id", "http://test.com/akn/test6.html"); doc.addField("Source2", "aknsource"); doc.addField("url", "http://test.com/akn/test6.html"); doc.addField("title", "SolrCloud rocks"); doc.addField("text", "This is a sample text"); UpdateResponse resp = server.add(doc); //UpdateResponse res = server.commit();
我有2个分片,每个分片有1个副本,还有一个zookeeper实例。
运行此测试代码后,我能够看到请求命中节点。 这是日志的输出:
INFO - 2013-09-26 03:19:04.981;
org.apache.solr.update.processor.LogUpdateProcessor; [collection1]
webapp=/solr path=/update params={distrib.from=
http://ec2-1-2-3-4.us-west-1.compute.amazonaws.com:8983/solr/collection1/&update.distrib=TOLEADER&wt=javabin&version=2}
{add=[http://test.com/akn/test6.html (1447223565945405440)]} 0 42
INFO - 2013-09-26 03:19:19.943;
org.apache.solr.update.DirectUpdateHandler2; start
commit{,optimize=false,openSearcher=false,waitSearcher=true,expungeDeletes=false,softCommit=false,prepareCommit=false}
INFO - 2013-09-26 03:19:20.249; org.apache.solr.core.SolrDeletionPolicy;
SolrDeletionPolicy.onCommit: commits: num=2
commit{dir=NRTCachingDirectory(org.apache.lucene.store.MMapDirectory@/mnt/ebs2/TestSolr44/solr/collection1/data/index
lockFactory=org.apache.lucene.store.NativeFSLockFactory@36ddc581;
maxCacheMB=48.0 maxMergeSizeMB=4.0),segFN=segments_7,generation=7}
commit{dir=NRTCachingDirectory(org.apache.lucene.store.MMapDirectory@/mnt/ebs2/Testolr44/solr/collection1/data/index
lockFactory=org.apache.lucene.store.NativeFSLockFactory@36ddc581;
maxCacheMB=48.0 maxMergeSizeMB=4.0),segFN=segments_8,generation=8}
INFO - 2013-09-26 03:19:20.250; org.apache.solr.core.SolrDeletionPolicy;
newest commit generation = 8
INFO - 2013-09-26 03:19:20.252; org.apache.solr.search.SolrIndexSearcher;
Opening Searcher@c324b85 realtime
INFO - 2013-09-26 03:19:20.254;
org.apache.solr.update.DirectUpdateHandler2; end_commit_flush
从日志中看,提交已成功完成。 但是如果我查询服务器,则没有条目出现。
现在,如果我打开
UpdateResponse res = server.commit();
我看到索引的数据。这是日志:
INFO - 2013-09-26 03:41:24.433;
org.apache.solr.update.processor.LogUpdateProcessor; [collection1]
webapp=/solr path=/update params={wt=javabin&version=2} {add=[
http://test.com/akn/test6.html (1447224970494083072)]} 0 12
INFO - 2013-09-26 03:41:24.490;
org.apache.solr.update.DirectUpdateHandler2; start
commit{,optimize=false,openSearcher=true,waitSearcher=true,expungeDeletes=false,softCommit=false,prepareCommit=false}
INFO - 2013-09-26 03:41:24.788; org.apache.solr.core.SolrDeletionPolicy;
SolrDeletionPolicy.onCommit: commits: num=2
commit{dir=NRTCachingDirectory(org.apache.lucene.store.MMapDirectory@/mnt/ebs2/TestSolr44/solr/collection1/data/index
lockFactory=org.apache.lucene.store.NativeFSLockFactory@36ddc581;
maxCacheMB=48.0 maxMergeSizeMB=4.0),segFN=segments_8,generation=8}
commit{dir=NRTCachingDirectory(org.apache.lucene.store.MMapDirectory@/mnt/ebs2/TestSolr44/solr/collection1/data/index
lockFactory=org.apache.lucene.store.NativeFSLockFactory@36ddc581;
maxCacheMB=48.0 maxMergeSizeMB=4.0),segFN=segments_9,generation=9}
INFO - 2013-09-26 03:41:24.788; org.apache.solr.core.SolrDeletionPolicy;
newest commit generation = 9
INFO - 2013-09-26 03:41:24.792; org.apache.solr.search.SolrIndexSearcher;
Opening Searcher@138ba593 main
INFO - 2013-09-26 03:41:24.794;
org.apache.solr.update.DirectUpdateHandler2; end_commit_flush
INFO - 2013-09-26 03:41:24.794; org.apache.solr.core.QuerySenderListener;
QuerySenderListener sending requests to
Searcher@138ba593main{StandardDirectoryReader(segments_9:21:nrt
_0(4.4):C1 _1(4.4):C1
_3(4.4):C1 _4(4.4):C1 _5(4.4):C1 _7(4.4):C1)}
INFO - 2013-09-26 03:41:24.795; org.apache.solr.core.QuerySenderListener;
QuerySenderListener done.
INFO - 2013-09-26 03:41:24.798; org.apache.solr.core.SolrCore;
[collection1] Registered new searcher
Searcher@138ba593main{StandardDirectoryReader(segments_9:21:nrt
_0(4.4):C1 _1(4.4):C1
_3(4.4):C1 _4(4.4):C1 _5(4.4):C1 _7(4.4):C1)}
INFO - 2013-09-26 03:41:24.798;
org.apache.solr.update.processor.LogUpdateProcessor; [collection1]
webapp=/solr path=/update
params={waitSearcher=true&commit=true&wt=javabin&expungeDeletes=false&commit_end_point=true&version=2&softCommit=false}
{commit=} 0 308
这是提交配置:
<autoCommit>
<maxTime>30000</maxTime>
<openSearcher>false</openSearcher>
</autoCommit>
<autoSoftCommit>
<maxTime>1000</maxTime>
</autoSoftCommit>
不确定我在这里缺少什么,任何指针都会被贬低。
由于
答案 0 :(得分:0)
在您包含的第一个日志中,它仅显示openSearcher = false的提交。这可确保正确刷新数据,但不会使其可搜索。这可能是因为配置的autoCommit部分而发生的。
您粘贴的配置代码段显示autoSoftCommit也有一秒的maxTime,但日志不会显示任何软提交。如果没有看到整个配置,就无法确定它是否真正有效。它可能被注释掉了。
答案 1 :(得分:0)
CloudSolrServer使用LoadBalanced HttpSolrServer,文档明确指出不会用来发出“写”命令:
NOT 使用此类在主/从方案中进行索引,因为必须将文档发送到正确的主服务器;没有完成节点间路由。
为什么不直接指向您的ZooKeeper(或包含ZooKeeper的分片)的常规HttpSolrServer并使用它来插入文档(ZooKeeper / master副本应该负责将它们发送到其他分片) ?
答案 2 :(得分:0)
您需要在solrconfig.xml文件中配置autosoft commit和hardcommit params。您可以做的更多事情是尝试通过CloudSolrServer使用commitWithin,因为它更灵活,更高效,然后硬提交。您将congifure硬提交间隔强制转换为arround 4 -5分钟(根据您的要求设置)。请参阅以下链接了解更多详情