簡體   English   中英

如何為Solr模式定義文檔級別和數據級別字段

[英]How to define a document level and data level field for a solr schema

我有一個名為test.csv的簡單文件,它具有以下數據

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

我希望在solr中為該文件建立索引,並將唯一的ID傳遞給它,名為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中,將schema.xml想象成一個數據庫表。 為了保持行的唯一性,我們在其中有一個主鍵列。 通常就像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'內容類型:文本/純文本; charset = 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。 所以我希望我已經回答了我自己的問題!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM