【问题标题】:msg=Multiple values encountered for non multiValued copy fieldmsg=非多值复制字段遇到多个值
【发布时间】:2021-06-02 09:47:55
【问题描述】:

我有更新值的字典,我想使用 python 代码用 solr 中的动态值更新字段值。例如我已经显示retweet_count 这个字段是动态的,只要它被改变。

它不应该是一个多值字段。

代码:

                    try:
                        if res['retweet_count'] != tweets['retweet_count']:
                            print "retweet increased  . . old retweets : ", res['retweet_count'], " new retweets : ", tweets['retweet_count']
                            res['retweet_count'] = tweets['retweet_count']
                    except KeyError:
                        print "retweet_count not in res"
                        res['retweet_count'] = tweets['retweet_count']
                    solr.add([res])

错误:

   Traceback (most recent call last):
      File "user.py", line 267, in <module>
        get_all_tweets(x)
      File "user.py", line 245, in get_all_tweets
        solr.add({'set':[res]})  # ==> solr
      File "/home//anaconda3/envs/TwitterINt/lib/python2.7/site-packages/pysolr.py", line 1050, in add
        solrapi=solrapi,
      File "/home//anaconda3/envs/TwitterINt/lib/python2.7/site-packages/pysolr.py", line 572, in _update
        {"Content-type": "application/json; charset=utf-8"},
      File "/home//anaconda3/envs/TwitterINt/lib/python2.7/site-packages/pysolr.py", line 463, in _send_request
        raise SolrError(error_message % (resp.status_code, solr_message))
    pysolr.SolrError: Solr responded with an error (HTTP 400): [Reason: ERROR: [doc=1059346579209936896] Error adding field 'retweet_count'='0' msg=Multiple values encountered for non multiValued copy field retweeted_count: 0]

【问题讨论】:

  • 您需要将 retweeted_count 字段定义为 multiValued="true"... 因为该字段是复制字段,并且将保存其他多个字段的值
  • 如果您可以共享定义的架构...会更好
  • 是的,但我不希望它是多值的!假设 retweeted_count = 5 有时它会 retweeted_count = 10 所以它应该更新。架构 -
  • 字段 name="retweet_count" 是复制字段吗?
  • 您是否将数组值传递给它?

标签: python apache solr solr4


【解决方案1】:

您需要将schema.xml中的字段retweet_count定义为multiValued="true"

这将帮助您解决错误。

您的字段定义如下所示。

<field name="retweet_count" type="mention_the_field_type" stored="true" indexed="true" multiValued="true" />

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多