【问题标题】:How to define a document level and data level field for a solr schema如何为 solr 模式定义文档级别和数据级别字段
【发布时间】:2013-05-10 22:07:31
【问题描述】:

我有一个名为 test.csv 的简单文件,它包含以下数据

id,author,title
1,sanjay,ABC
2,vijay,XYZ

我希望在 solr 中索引这个文件并向它传递一个名为 id=1 的唯一 ID索引许多带有文档 id 的此类文件,例如 id=2、id=3 等。

在我的 schema.xml 中,id 是一个字段

 <field name="id" type="string" indexed="true" stored="true" />

 <!-- Field to use to determine and enforce document uniqueness.
  Unless this field is marked with required="false", it will be a required field
 -->
 <uniqueKey>id</uniqueKey>

并且文件中不存在 id 的实例,但我想将 id 作为参数传递给文档级别的唯一性,它会发出以下错误

 [root@****ltest1 garyTestDocs]# curl  http://localhost:8983/solr/update/csv?id='SL1' --data-binary @sample.csv -H    'Content-type:text/plain; charset=utf-8'
 <html>
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
 <title>Error 400 [doc=null] missing required field: ref</title> 
 </head>
 <body><h2>HTTP ERROR 400</h2> 
 <p>Problem accessing /solr/update/csv. Reason:
 <pre>    [doc=null] missing required field: id</pre></p><hr /><i><small>Powered by  Jetty://</small></i><br/>                                                
 <br/>                                                
 <br/>                                                
 <br/>                                                
 <br/>                                                
 <br/>                                                
 <br/>                                                

 </body>
 </html>

所以本质上有两种情况,在文件中使用 id 列索引上述示例文件,另一种情况是具有 id 列。但在这两种情况下,我都需要传递文档级别的唯一 ID,即 id='1' 或 id='2'。

您能否用这两种情况以及 curl 语法和 schema.xml(仅需要的字段)来解释您的答案

【问题讨论】:

    标签: solr


    【解决方案1】:

    在 Solr 中,将 schema.xml 想象为一个 DB 表。为了保持行的唯一性,我们在其中有一个主键列。通常像其中具有唯一值的 id 列。当您在 solr 中为文档编制索引时,例如在我的案例中包含列的 csv 文件。 id 列必须是唯一的,并且不能有空行。有很多方法可以创建唯一的字符串,但只是为了例如我使用了格式 file_name_1 ...(有一个填充系列,如 1,2,3...)。这是在 solr 中指定记录唯一性的唯一方法。您不能拥有文档级别的唯一性,这意味着在索引时无法提供唯一键。因此,在 schema.xml 中,您有一个唯一的键标记,它只不过是文档中将是唯一的列。

    用于索引 csv 文件的 qry 如下:-

    curl http://:8983/solr/update/csv --data-binary @Sample.csv -H 'Content-type:text/plain;字符集=utf-8'

    schema.xml 将有一个 id col

     <field name="id" type="string" indexed="true" stored="true" />
    

    我的文档中的一些列

     <field name="author" type="text" indexed="true" stored="true" />
     <field name="title" type="text" indexed="true" stored="true" />
    
    
     <uniqueKey>id</uniqueKey>
    

    索引时我没有使用文档级别的唯一 ID。所以我希望我已经回答了我自己的问题!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-02-16
      • 1970-01-01
      • 1970-01-01
      • 2015-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多