How to upload pdf and update field within one request in solr

北城余情 提交于 2019-12-13 04:13:22

问题


All:

I am new to solr and solrj. What I want to do right now is uploading pdf file to solr and set customized field such as last_modified field at same time.

But I keep encounter the error such as " multiple values encountered for non multiValued field last_modified", I use solrj to upload pdf and set the last_modified field like

ContentStreamUpdateRequest up = new ContentStreamUpdateRequest("/update/extract");
up.setParam("literal.last_modified", "2011-05-19T09:00:00Z");

I guess the error is due to when solr extract the pdf, it uses some meta data as last_modified field value as well so that my custmized last_modified value leads to a multivalue error, but I wonder how to replace the meta data with my custmized data?

Thanks


回答1:


/update/extract is defined in solrconfig.xml for your core. You can see the configuration there and modify it to match it to your particular scenario. The Reference Guide lists the options.

In your particular scenario, something look strange. The parameter that seems to be relevant is literalsOverride but it is true by default. Perhaps, you are setting it to false somewhere.

You can also try explicitly map Tika's last update field to some different name.

I would enable catch-all (dynamicField *) as store=true and see what is being captured. Then you can play with the parameters until you are happy. You don't have to restart Solr, just reload the core from the Admin UI.




回答2:


I have faced similar issue, where I need to fetch one dynamic field value and do some operation then update it. I use below code to achieve this. First check for that field is it exist or not. Try using below code may be it will help you.

    Map<String, String> partialUpdate = new HashMap<String, String>();
    if(alreadyPresent)
        {
            partialUpdate.put("set", value);
        }else
        {
            partialUpdate.put("add", value); 
        }

        doc.addField("projectId", projectId); // unique id for solrdoc 
        doc.addField(keys[0], partialUpdate); 

        docs.add(doc);
        solrServer.add(docs);
        solrServer.commit();


来源:https://stackoverflow.com/questions/27806002/how-to-upload-pdf-and-update-field-within-one-request-in-solr

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!