Solr4.0 如何配置使用UUID自动生成id值

2019-03-27 01:18|来源: 网路

   最近学习了Lucene,随便也学习了Solr,Solr规定每一条记录必须有一个主键值,用来唯一标识一条索引的记录,默认是使用id字段来作主键的(可以通过修改schema.xml文件更改),最烦的是这个主键不能设置自动增长,所以每添加一条记录,不得不手动为id字段赋值,如果不小心重复了,还很恶心的直接覆盖了原来的记录,所以在编程的时候不得不通过一些途径来维护这个id值,通过google发现了一个可以自动生成id值的方法,即让solr自动生成UUID值(Universal Unique Identifiers通用唯一标识符),这样编程的时候就不用维护这个id值了,使用这种做法的缺点就是:id值不是数值连续的,它是一串字符,如:5bb977a7-8a4c-46d6-ae49-b4eefade080c

具体配置如下:(这是Solr 4.0的配置

一、配置schema.xml文件

1、添加fieldType

<types>
    <!-- other field types -->
    <fieldType name="uuid" class="solr.UUIDField" indexed="true" />
</types>

2、添加主键id字段配置(注释或者删除原来的id字段配置,切记

<field name="id" type="uuid" indexed="true" stored="true" required="true" multiValued="false" />

二、配置solrconfig.xml文件

1、注释掉以下的配置,原因及可能产出的异常参考:https://issues.apache.org/jira/browse/SOLR-3398

  <searchComponent name="elevator" class="solr.QueryElevationComponent" >
    <str name="queryFieldType">string</str>
    <str name="config-file">elevate.xml</str>
  </searchComponent>
2、添加一个updateRequestProcessorChain配置

<updateRequestProcessorChain name="uuid">
    <processor class="solr.UUIDUpdateProcessorFactory">
        <str name="fieldName">id</str>
    </processor>
    <processor class="solr.RunUpdateProcessorFactory" />
</updateRequestProcessorChain>
3、修改其中一个requestHandler配置, 注意:上一步是添加,而这里是修改,如果直接添加的话,那么就会重复配置,这样后面的配置会覆盖前面的配置,本人就是很不幸的被默认的配置覆盖了我添加的配置,当时够郁闷的!

<requestHandler name="/update" class="solr.UpdateRequestHandler">
    <!-- See below for information on defining 
         updateRequestProcessorChains that can be used by name 
         on each Update Request
      -->
 	<!--
       <lst name="defaults">
         <str name="update.chain">dedupe</str>
       </lst>
       -->
	<lst name="defaults">
        <str name="update.chain">uuid</str>
    </lst>
  </requestHandler>








转自:http://blog.csdn.net/KeepThinking_/article/details/8501058

相关问答

更多
  • http://wenku.baidu.com/view/5796f25e2b160b4e767fcfd8.html 我自己整理的比交全的Solr调研文档.应该有用. 本文介绍solr的功能使用及相关注意事项;主要包括以下内容:环境搭建及调试、两个核心配置文件介绍、中文分词器配置、维护索引、查询索引,高亮显示、拼写检查、搜索建议、分组统计、自动聚类、相似匹配、拼音检索等功能的使用方法
  • 1. commit 有返回值的 UpdateResponse updateResponse = solrServer.commit();int status = updateResponse.getStatus()这里的 status 可以拿到操作执行的状态 ,0表示 成功 if (status != 0) { log.error("Some horrible error has occurred, status is:" + status); } 2. try{ UpdateResponse addBea ...
  • 好的,我发现了。 如果有人感兴趣:longs似乎在Solr 4.0中使用不同类型的编码,所以我们可以像上面的代码一样将它们作为普通字符串处理,但后来我们必须使用不同的解析器将term值转换为long: FieldCache.NUMERIC_UTILS_LONG_PARSER.parseLong(term) 当没有更多元素存在时,它似乎抛出异常。 至于现在它工作正常。 Ok, i found it out. If anyone is interested: longs seem to use differ ...
  • 通常,如果仅指定过滤器查询( fq ),则不会返回任何结果。 (更准确地说,如果未指定q参数,则默认为“匹配无文档”查询。) 将q参数设置为[* TO *]匹配默认字段中的所有值(现在看起来*将执行相同的操作),因此您应该返回相同的结果集,但不一定是相同的顺序,如果您将第二个查询修改为: http://localhost:8983/solr/collection1/select?fq={!join+from=id+to=manu_id_s+cache=false}id:*&q=[*+TO+*] fq不会影 ...
  • 使用solr 4.0, BaseTokenFilterFactory现在是org.apache.lucene.analysis.util.TokenFilterFactory ,所以你可以检查一下 。 With solr 4.0 the BaseTokenFilterFactory is now org.apache.lucene.analysis.util.TokenFilterFactory, so you can check on this.
  • 随着id被修复,您可以使用过滤器查询来搜索多个ID,这对于使用过滤器缓存的性能也是最好的,例如 fq=VersionId:(5d4cb2a7-198b-4e26-a003-3b0388e35820 OR 5d4cb2a7-198b-4e26-a003-3b0388e35820 OR 5d4cb2a7-198b-4e26-a003-3b0388e35820 .....) As the id is fixed you can use filter query to search multiple ids wo ...
  • 您可以跨不同的核心加入语法,例如: {!from from = fromId to = toId fromIndex = Core2}查询 所以如果你有两个核心看起来像 PersonCore - ID,名称 AddressCore - ID,地址,PersonID 您可以通过查询PersonCore找到特定地址的所有人,如下所示: {!join from=PersonID to=ID fromIndex=AddressCore}Address:Address1 您只能拥有一个UniqueKey。 有可能自 ...
  • 找到答案: 阅读更多文档 :页 由于langid被配置为更新请求处理器链,因此它需要被选中(它不是自动的)。 所以,这工作: curl "http://localhost:8983/solr/update/extract?literal.id=test&commit=true&update.chain=langid" -F "myfile=@test.xml" Found the answer: read more docs :p Since langid is configured as an upda ...
  • 试试这个curl命令: curl http://localhost:8983/solr//update?commit=true -H 'Content-type:application/json' --data-binary '' 请适当地替换corename和data参数。 Try this curl command: curl http://localhost:8983/solr//update?commit=true -H 'Content-typ ...
  • 除了新功能之外,Solr 3.6和Solr 4.0之间是否有任何重大差异? 我发现这个问题很奇怪,至少可以说。 错误修复和新功能是发布的全部内容! 您可以在此处查看 Solr版本的完整更新日志。 不要忘记Solr和Lucene是一致发布的,所以你还需要在两个项目中寻找相关的变化。 我可以安全地使用我在Solr 4.0中的现有查询(在Solr 3.6中工作的查询)吗? 查询应该没问题,但索引 - 可能不是。 引用另一篇SO帖子中的 javanna: 索引格式已更改,但Solr将负责升级索引。 一旦用旧索引启动 ...