文档

索引数据可见性

更新时间:

写入Search服务中的数据,只有等到commit后才是可见的,何时执行commit是可以配置的,当前有两种commit方式:soft commit、hard commit。

solrconfig.xml中的配置

创建索引时需要指定配置集config set,配置集中的solrconfig.xml文件可以用来控制索引数据的可见性。如何获取solrconfig.xml,请参见更新配置集

  • soft commit

    <autoSoftCommit>
      <maxTime>${solr.autoSoftCommit.maxTime:15000}</maxTime>
    </autoSoftCommit>
                            

    写入的数据15秒后可以查询。

  • hard commit

    <autoCommit>
      <maxTime>${solr.autoCommit.maxTime:30000}</maxTime>
      <openSearcher>false</openSearcher>
    </autoCommit>
                            

    写入的数据30秒后刷新到磁盘中。

    说明
    • soft commit的时间要小于hard commit时间。

    • 一般不建议配置较小的时间,这会导致服务端频繁刷新和open searcher,影响写入性能。采用默认值即可。

如何生效

  1. 下载需要修改的配置集,请参见更新配置集

  2. 修改soft commithard commit的时间。

  3. 更新配置集。

    ./solr zk upconfig -d conf/ -n myconf
                        
  4. Collections页面,选中目标Collection,单击Reloadreload索引

客户端参数

如果不想修改服务端的solrconfig.xml文件,在单独写数据到Search时可以显示调用commit来达到数据可见的目的。

  • commitWithinMs

    // 第二个参数commitWithinMs可以控制当前写入的数据多久后可以查询。
    public UpdateResponse add(SolrInputDocument doc, int commitWithinMs) throws SolrServerException, IOException;
    //例如:代表10秒后数据可查询。
    cloudSolrClient.add(doc, 1000); 
                        
  • commit API

    // 写完数据后,显示调用commit接口,让服务端在多久后执行commit,保证数据可查询。
    public UpdateResponse commit(boolean waitFlush, boolean waitSearcher, boolean softCommit) throws SolrServerException, IOException;
    //例如:服务端立即执行soft commit。
    cloudSolrClient.commit(false, false, true);
                        

参考文档

请参见官方文档

  • 本页导读 (1)
文档反馈