在Solr中,每一个索引,都要有一个唯一的ID,类似于关系型数据库表中的主键。为了方便创建索引,需要配置自动生成的ID,即UUID。

一、配置schema.xml文件

添加uuid字段类型,修改字段id的类型。

   <field name="id" type="uuid" indexed="true" stored="true" required="true" multiValued="false" />
<fieldType name="uuid" class="solr.UUIDField" indexed="true" />

二、配置solrconfig.xml文件

添加更新策略配置,调用Solr中的UUIDUpdateProcessorFactory生成全局唯一的UUID。

<updateRequestProcessorChain name="uuid">
<processor class="solr.UUIDUpdateProcessorFactory">
<str name="fieldName">id</str>
</processor>
<processor class="solr.LogUpdateProcessorFactory" />
<processor class="solr.DistributedUpdateProcessorFactory" />
<processor class="solr.RunUpdateProcessorFactory" />
</updateRequestProcessorChain>

配置requestHandler,保证dataimport和update操作都可以自动生成UUID。

<requestHandler name="/dataimport" class="solr.DataImportHandler">
<lst name="defaults">
<str name="config">tika-data-config.xml</str>
<str name="update.chain">uuid</str>
</lst>
</requestHandler> <requestHandler name="/update" class="solr.UpdateRequestHandler">
<lst name="defaults">
<str name="update.chain">uuid</str>
</lst>
</requestHandler> <!-- for back compat with clients using /update/json and /update/csv -->
<requestHandler name="/update/json" class="solr.JsonUpdateRequestHandler">
<lst name="defaults">
<str name="stream.contentType">application/json</str>
<str name="update.chain">uuid</str>
</lst>
</requestHandler>
<requestHandler name="/update/csv" class="solr.CSVRequestHandler">
<lst name="defaults">
<str name="stream.contentType">application/csv</str>
<str name="update.chain">uuid</str>
</lst>
</requestHandler> <requestHandler name="/update/extract"
startup="lazy"
class="solr.extraction.ExtractingRequestHandler" >
<lst name="defaults">
<str name="xpath">/xhtml:html/xhtml:body/descendant:node()</str>
<str name="capture">content</str>
<str name="fmap.meta">attr_meta_</str>
<str name="uprefix">attr_</str>
<str name="lowernames">true</str>
<str name="update.chain">uuid</str>
</lst>
</requestHandler>

经过以上配置之后,在进行索引的时候,就不需要指定ID了,Solr可自动生成ID字符串。

Solr自动生成ID的更多相关文章

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

    原文链接http://blog.csdn.net/keepthinking_/article/details/8501058#comments 最近学习了Lucene,随便也学习了Solr,Solr规 ...

  2. mybatis多表查询,自动生成id

    主要是在配置文件中,配置好所要包含的字段. 类关系:account----role,1对1 account包含role类 java类: public class Account{ private In ...

  3. ASP.NET 4.0 ListView等容器控件中获取ClientID值与HTML中自动生成ID字符串不一样问题。

    ASP.NET 4.0 中 ClientIDMode的属性 可以设置获取不同ID格式的值. 项目中遇到的问题: 1.ListView1 ItemDataBound事件中,获取ClientID结果与自动 ...

  4. Elasticsearch 索引文档如何使用自动生成 Id?

    一个文档的 _index . _type 和 _id 唯一标识一个文档. 我们可以提供自定义的 _id 值,或者让 index API 自动生成. 如果你的数据没有自然的 ID, Elasticsea ...

  5. oracle中利用trigger,sequence自动生成ID

    http://zhanghong.iteye.com/blog/865937 1. 首先创建数据库表 SQL> create table customer( 2  id number(8) no ...

  6. 自动生成ID

    public class IdUtil { /** * * @return 返回时间id,类似于20191217195622 */ public static String timeId(){ Dat ...

  7. 系统自动生成ID(比UUID.radom().tostring()要好看)

    public class test1 { public static void main(String[] args) { char[] para = {'A','B','C','D','E','F' ...

  8. MySQL 之 数据库自动生成ID格式化编号(字符串格式化填充/拼接/时间)

    # 用户账号:1-4位:入职年份:5-6位:入职月份:7-11位:员工入职顺序号 select concat( date_format(now(),'%Y'), date_format(now(),' ...

  9. solr亿万级索引优化实践-自动生成UUID

    solr亿万级索引优化实践(三) 原创 2017年03月14日 17:03:09        本篇文章主要介绍下如何从客户端solrJ以及服务端参数配置的角度来提升索引速度. solrJ6.0提供的 ...

随机推荐

  1. rowspan和colspan

    1.说明 rowspan:跨行colspan:跨列用于设计复杂的表格 2.例子<!DOCTYPE html> <html> <head> <meta char ...

  2. Matlab:回归分析(1)

    1.多元线性回归 %数据的输入 x = [ ]; y = [ ]; %转换为列向量 X = [ones(,) x']; Y = y'; %回归分析及检验 [b, bint, r, rint, stat ...

  3. Flume源码-LoggerSink

    package org.apache.flume.sink; import com.google.common.base.Strings; import org.apache.flume.Channe ...

  4. war文件

    原文地址:http://blog.sina.com.cn/s/blog_4cbc6fdd0100fojv.html jar包和war包的区别:war是一个web模块,其中需要包括WEB-INF,是可以 ...

  5. PHP学习之[第01讲]开启PHP学习之路,融入新互联网时代

    小编本身现在是手机应用客户端开发者,包括iOS和Android. 学习PHP有两个目的: 1.为移动端提供服务: 2.向后台项目的架构方面学习.

  6. 【.NET跨平台】mac上安装VS for mac步骤详解

    安装过程中提示以下内容 提示原文如下 It was not possible to complete an automatic installation. This might be due to a ...

  7. Android NumberPicker默认外观的修改

    NumberPicker是Android3.0之后引入的一个控件,在以后的TimePicker和DatePicker时间控件里边都有引用,NumberPicker本身并没有提供接口给开发者修改其默认外 ...

  8. N皇后问题--递归回溯

    著名的N皇后问题,就是先按照行一行一行的找,先找第一行,第一行找到一列能满足条件,继续找下一行,如果下一行也找到一列能满足条件,继续找下一行,一次类推,最终找到解, 但是,如果找不到的话, 就说明上一 ...

  9. css中同时用头部引入和外部引入对同一个标签进行样式设置,哪一个优先级高。

    这段是html中的代码 <!doctype html> <html lang="en"> <head> <meta charset=&qu ...

  10. 使用SQL Server CONVERT() 函数

    语法 CONVERT(data_type(length),data_to_be_converted,style) data_type(length) 规定目标数据类型(带有可选的长度).data_to ...