Solr异常:文档缺少必需的uniqueKey字段:id

时间:2014-07-29 00:37:11

标签: solr

我在尝试插入行时遇到上述错误...我的架构在下面给出,我使用相同的id字段

Python code:

import solr

# create a connection to a solr server
s = solr.SolrConnection('http://127.0.0.1:8983/solr')

# add a document to the index
doc = dict(
    id="1",
    name='Lucene in Action',
    author_name='ErikHatcher',
    )
print doc
s.add(doc,commit=True)

# do a search
response = s.query('title:lucene')
for hit in response.results:
    print hit['title']


Error:

ERROR - 2014-07-29 00:29:09.752; org.apache.solr.common.SolrException; org.apache.solr.common.SolrException: Document is missing mandatory uniqueKey field: id
        at org.apache.solr.update.AddUpdateCommand.getIndexedId(AddUpdateCommand.java:92)
        at org.apache.solr.update.processor.DistributedUpdateProcessor.versionAdd(DistributedUpdateProcessor.java:717)
        at org.apache.solr.update.processor.DistributedUpdateProcessor.processAdd(DistributedUpdateProcessor.java:557)
        at org.apache.solr.update.processor.LogUpdateProcessor.processAdd(LogUpdateProcessorFactory.java:100)
        at org.apache.solr.handler.loader.XMLLoader.processUpdate(XMLLoader.java:247)

     

   <!-- Table Field -->
   <field name="name" type="string" indexed="true" stored="true" multiValued="false"/>
   <field name="slug" type="string" indexed="true" stored="true" multiValued="false"/>
   <field name="author_name" type="string" indexed="true" stored="true" multiValued="false"/>
   <field name="sku" type="string" indexed="true" stored="true" multiValued="false"/>
   <field name="price" type="string" indexed="true" stored="true" multiValued="false"/>
   <field name="Old_price" type="string" indexed="true" stored="true" multiValued="false"/>
   <field name="is_active" type="string" indexed="true" stored="true" multiValued="false"/>
   <field name="is_bestseller" type="string" indexed="true" stored="true" multiValued="false"/>
   <field name="is_featured" type="string" indexed="true" stored="true" multiValued="false"/>
   <field name="description" type="string" indexed="true" stored="true" multiValued="false"/>
   <field name="meta_keywords" type="string" indexed="true" stored="true" multiValued="false"/>
   <field name="meta_description" type="string" indexed="true" stored="true" multiValued="false"/>
   <field name="created_at" type="string" indexed="true" stored="true" multiValued="false"/>
   <field name="updated_at" type="string" indexed="true" stored="true" multiValued="false"/>
   <field name="image" type="string" indexed="true" stored="true" multiValued="false"/>
   <field name="thumbnail" type="string" indexed="true" stored="true" multiValued="false"/>
   <field name="image_caption" type="string" indexed="true" stored="true" multiValued="false"/>
   <field name="category" type="string" indexed="true" stored="true" multiValued="false"/>

 <field name="content" type="text_general" indexed="false" stored="true" multiValued="true"/>


   <!-- catchall field, containing all other searchable text fields (implemented
        via copyField further on in this schema  -->
   <field name="text" type="text_general" indexed="true" stored="false" multiValued="true"/>

   <!-- catchall text field that indexes tokens both normally and in reverse for efficient
        leading wildcard queries. -->
   <field name="text_rev" type="text_general_rev" indexed="true" stored="false" multiValued="true"/>

   <!-- non-tokenized version of manufacturer to make it easier to sort or group
        results by manufacturer.  copied from "manu" via copyField -->
   <field name="manu_exact" type="string" indexed="true" stored="false"/>

   <field name="payloads" type="payloads" indexed="true" stored="true"/>

<field name="_version_" type="long" indexed="true" stored="true"/>
<dynamicField name="*_i"  type="int"    indexed="true"  stored="true"/>
   <dynamicField name="*_is" type="int"    indexed="true"  stored="true"  multiValued="true"/>
   <dynamicField name="*_s"  type="string"  indexed="true"  stored="true" />
   <dynamicField name="*_ss" type="string"  indexed="true"  stored="true" multiValued="true"/>
   <dynamicField name="*_l"  type="long"   indexed="true"  stored="true"/>
   <dynamicField name="*_ls" type="long"   indexed="true"  stored="true"  multiValued="true"/>
   <dynamicField name="*_t"  type="text_general"    indexed="true"  stored="true"/>
   <dynamicField name="*_txt" type="text_general"   indexed="true"  stored="true" multiValued="true"/>
   <dynamicField name="*_en"  type="text_en"    indexed="true"  stored="true" multiValued="true"/>
   <dynamicField name="*_b"  type="boolean" indexed="true" stored="true"/>
   <dynamicField name="*_bs" type="boolean" indexed="true" stored="true"  multiValued="true"/>
   <dynamicField name="*_f"  type="float"  indexed="true"  stored="true"/>
   <dynamicField name="*_fs" type="float"  indexed="true"  stored="true"  multiValued="true"/>
   <dynamicField name="*_d"  type="double" indexed="true"  stored="true"/>
   <dynamicField name="*_ds" type="double" indexed="true"  stored="true"  multiValued="true"/>

   <!-- Type used to index the lat and lon components for the "location" FieldType -->
   <dynamicField name="*_coordinate"  type="tdouble" indexed="true"  stored="false" />

   <dynamicField name="*_dt"  type="date"    indexed="true"  stored="true"/>
   <dynamicField name="*_dts" type="date"    indexed="true"  stored="true" multiValued="true"/>
   <dynamicField name="*_p"  type="location" indexed="true" stored="true"/>

   <!-- some trie-coded dynamic fields for faster range queries -->
   <dynamicField name="*_ti" type="tint"    indexed="true"  stored="true"/>
   <dynamicField name="*_tl" type="tlong"   indexed="true"  stored="true"/>
   <dynamicField name="*_tf" type="tfloat"  indexed="true"  stored="true"/>
   <dynamicField name="*_td" type="tdouble" indexed="true"  stored="true"/>
   <dynamicField name="*_tdt" type="tdate"  indexed="true"  stored="true"/>

   <dynamicField name="*_pi"  type="pint"    indexed="true"  stored="true"/>
   <dynamicField name="*_c"   type="currency" indexed="true"  stored="true"/>

   <dynamicField name="ignored_*" type="ignored" multiValued="true"/>

   

 ID

2 个答案:

答案 0 :(得分:1)

solrpy文档中有一个不幸的错误。文档说你传递了add()一个字典,但这是不正确的,也是问题的根源。

从源代码(core.py):

  add(**params)

            Add a document.  Pass in all document fields as
            keyword parameters:

                add(id='foo', notes='bar')

            You must "commit" for the addition to be saved.

您可以看到正确的方法是在逗号分隔的列表中传递keyword = value参数,而不是dict。如果你进行这种调整,我相信它会正常工作。

答案 1 :(得分:0)

请在schema.xml文件中添加<field name="id" XXXXXXXX />

进行更改后,您可以重新启动SOLR实例,或者如果您使用的是SOLR4.0 +,则可以执行 RELOAD 命令,以便在SOLR中反映更改。

http://technical-fundas.blogspot.in/2014/07/solr-reload-solrconfigxml-and-schemaxml.html

HTH,

Jayesh Bhoyar