Reputation: 5731
How do I add multivalued fields when I'm using the Extracting Request Handler?
The documentation says
literal.<fieldname>
Populates a field with the name supplied with the specified value for each document. The data can be multivalued if the field is multivalued.|
Using code looking roughly like this
HttpSolrClient solr = new HttpSolrClient.Builder("http://localhost:8983/solr/myindex").build();
solr.setParser(new XMLResponseParser());
ContentStreamUpdateRequest req = new ContentStreamUpdateRequest("/update/extract");
ContentStream contentStream = new ContentStreamBase.ByteArrayStream(bytes, xxx);
req.addContentStream(contentStream);
req.setParam("literal.id", id);
...
req.setParam("literal.keywords", "[foo,bar]"); // Not working
req.setAction(req.getAction().COMMIT, true, true);
I have tried several ways of adding multiple values, but it comes out as a literal literal. What I've tried:
req.setParam("literal.keywords", "foo,bar");
---
req.setParam("literal.keywords", "[foo,bar]");
---
req.setParam("literal.keywords", "[\"foo\",\"bar\"]");
---
req.setParam("literal.keywords", "foo");
req.setParam("literal.keywords", "bar");
None of these results in a list in the index. Any ideas?
Upvotes: 1
Views: 147
Reputation: 5731
I found a solution:
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("literal.keywords", "foo", "bar");
params.set("literal.id", resourceUrl);
...
req.setParams(params);
The ModifiableSolrParams
can handle varargs, which setParam can't.
Upvotes: 1