solrj api for partial document update - solr

Solr 4 beta is out, the GA version will follow soon. Partial document updates has been around for a while as explained here: http://solr.pl/en/2012/07/09/solr-4-0-partial-documents-update/
However, I haven't figured out how to do it with solrj api.
Does anyone knows if it is possible with solrj? Or is solrj just not up-to-speed with this feature?
update: as I describe in the mailing list (see reply here), I found that in the solrj api, the value of a SolrInputField can be a map - it doesn't have to be a simple scalar value.
If it is a map, solrj adds an additional update attribute to the field's xml element.
For example,
This code:
SolrInputDocument doc = new SolrInputDocument();
Map<String, String> partialUpdate = new HashMap<String, String>();
partialUpdate.put("set", "foo");
doc.addField("id", "test_123");
doc.addField("description", partialUpdate);
yields this document:
<doc boost="1.0">
<field name="id">test_123</field>
<field name="description" update="set">foo</field>
</doc>
In this example I used the word "set" for this additional attribute, but it doesn't work.
Solr doesn't update the field as I expected.
According to this link:
http://solr.pl/en/2012/07/09/solr-4-0-partial-documents-update/
valid values are "set" and "add".
Any idea?

As it turns out, the code snippet shown above in the question actually works. I don't know what was wrong the first time I tried it, perhaps I simply forgot to commit or my schema was misconfigured.
In any case, this question is very localized. However, since the api with the hash map is so poorly documented, I thought maybe it is worth to keep this question and answer.
The key of the hash map can be one of three values:
set - to set a field.
add - to add to a multi-valued field.
inc - to increment a field.
There is an example of this code in the solrj unit tests, in a method called testUpdateField.

You can update parts of documents using the SOLR API's update endpoint
curl 'https://solr-url/update?commitWithin=1000&overwrite=true&wt=json' \
-X POST \
-H 'accept: application/json, text/plain, */*' \
--data-raw '[{ "the-unique-filed": "value", "field-to-change":{"set": "new-value"} }]' \
--compressed
Or from UI

Related

Ordering the solr search results based on the indexed fields

I have to order the search results from solr based on some fields which are already indexed.
My current api request is like this without sorting.
http://127.0.0.1:8000/api/v1/search/facets/?page=1&gender=Male&age__gte=19
And it gives the search results based on the indexed order. But I have to reorder this results based on the filed 'last_login' which is already indexed DateTimeField.
Here is my viewset
class ProfileSearchView(FacetMixin, HaystackViewSet):
index_models = [Profile]
serializer_class = ProfileSearchSerializer
pagination_class = PageNumberPagination
facet_serializer_class = ProfileFacetSerializer
filter_backends = [HaystackFilter]
facet_filter_backends = [HaystackFilter, HaystackFacetFilter]
def get_queryset(self, index_models=None):
if not index_models:
index_models = []
queryset = super(ProfileSearchView, self).get_queryset(index_models)
queryset = queryset.order_by('-created_at')
return queryset`
Here I have changed the default search order by 'created_at' value. But for the next request I have order based on the 'last_login' value. I have added a new parameter in my request like this
http://127.0.0.1:8000/api/v1/search/facets/?page=1&gender=Male&age__gte=19&sort='last_login'
but it gives me an error
SolrError: Solr responded with an error (HTTP 400): [Reason: undefined field sort]
How can I achieve this ordering possible? Please help me with a solution.
The URL you provided http://127.0.0.1:8000/api/v1/search/facets/ is not direct SOLR URL. It must be your middle-ware. Since you have tried the query directly against Solr and it works, the problem must be somewhere in middle-ware layer.
Try to print or monitor or check logs to see what URL the midde-ware actually generates and compare it to the valid URL you know works.

How to fetch data from couchDB using couch api?

Instead keys and IDs alone, I want to get all the docs via couch api. I have tried with GET "http://localhost:5984/db-name/_all_docs" but it returned
{
"total_rows":4,
"offset":0,
"rows":[
{"id":"11","key":"11","value":{"rev":"1-a0206631250822b37640085c490a1b9f"}},
{"id":"18","key":"18","value":{"rev":"30-f0798ed72ceb3db86501c69ed4efa39b"}},
{"id":"3","key":"3","value":{"rev":"15-0dcb22bab2b640b4dc0b19e07c945f39"}},
{"id":"6","key":"6","value":{"rev":"4-d76008cc44109bd31dd32d26ba03125d"}}
]
}
From the documentation
for the below request it will send the data as we expected but it requires set of keys in request.
POST /db/_all_docs HTTP/1.1
{
"keys" : [
"11",
"18"
]
}
Thanks in advance.
The _all_docs endpoint is actually just a system-level view that uses the _id field as the index. Thus, any parameters that you can use for views also apply here.
If you read the documentation further, you'll find that adding the parameter include_docs=true to your view will include the original documents in the results. The documents will be added as the doc field alongside id, value and rev.

Programmatically include xhtml fragment in MyFaces

I know it is possible in MyFaces to programmatically add a xhtml fragment to the component tree, instead of using ui:include.
The snipplet I am talking about is as (in the original form):
ViewDeclarationLanguage vdl = facesContext.getApplication().getViewHandler().getViewDeclarationLanguage(facesContext, facesContext.getViewRoot().getViewId());
Map<String, Object> attributes = new HashMap<String, Object>();
attributes.put("src", "/fragmentToInclude.xhtml");
UIComponent component = vdl.createComponent(facesContext, "http://java.sun.com/jsf/facelets", "include", attributes);
The problem I am facing is I am not able to pass in parameters, that would normally be passed in via <ui:param .../> tag.
What I tried, of course, was to add params into attributes map:
attributes.put("testingParam1", "Yeah, it worked!");
But this seems not to help. Content of my testing fragment is quite simple:
<ui:composition xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<div class="testingDiv">#{empty testingParam1 ? 'testingParam1 IS EMPTY' : testingParam1}</div>
</ui:composition>
The fragment is properly loaded, but I only get that 'is empty' message.
I have walked through multiple resources but haven't found answer there:
NullPointerException in MyFaces facelet inclusion
http://lu4242.blogspot.cz/2014/01/whats-new-in-myfaces-22.html
https://java.net/projects/javaserverfaces-spec-public/lists/jsr344-experts/archive/2014-03/message/12
https://java.net/projects/javaserverfaces-spec-public/lists/users/archive/2014-10/message/120
Please, do you know, is this even possible? Or am I missing something? Thanks for any hints.

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

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
/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.
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();

SalesForce Bulk API: Relationship between custom object and Account

I have a custom object in SalesForce called Deal, which is a child of the built-in Account object. I am trying to use the Bulk XML API to upload a batch of records, but I can't seem to figure out how to specify this relationship correctly. From the documentation it says that you should reference a custom object's relationships like so:
<Relationship__r>
<sObject>
<some_indexed_field>#####</some_indexed_field>
</sObject>
</Relationship__r>
If you have any idea how to specify a relationship to the Account object from a custom object I'd really appreciate it.
Added
The Deal object has the following 2 fields:
DealID
API Name - DealID__c
Data Type - Text(255)(External ID)(Unique Case Sensitive)
Account
API Name - Account__c
Data Type - Master-Detail(Account)
Request XML:
<Account__r>
<sObject>
<ID>0013000000kcWpfAAE</ID>
</sObject>
</Account__r>
Result XML:
<result>
<errors>
<message>Field name provided, Id is not an External ID or indexed field for Account</message>
<statusCode>INVALID_FIELD</statusCode>
</errors>
<success>false</success>
<created>false</created>
</result>
There appears to be a bug and you have to strip out all whitespace and newlines when dealing with reference objects.
Check out:
http://success.salesforce.com/ideaview?id=08730000000ITQ7AAO
From the docs
<RelationshipName>
<sObject>
<IndexedFieldName>rwilliams#salesforcesample.com</IndexedFieldName>
</sObject>
Everything looks good, but instead of using "ID" for the Indexed Field Name, you need to use "Account__c". That should take care of your issue.

Resources