This works for me, admittedly with the 3.3 code base:
Hmmm, did you *store* the dynamic fields? only stored fields are returned....
CommonsHttpSolrServer server = new
CommonsHttpSolrServer("http://localhost:8983/solr");
SolrQuery query = new SolrQuery();
query.setQuery("*");
query.setRows(1000);
QueryResponse qr = server.query(query, SolrRequest.METHOD.POST);
for (Object obj : qr.getHeader()) log(obj.toString());
SolrDocumentList sdl = qr.getResults();
for (SolrDocument d : sdl) {
// Print out all the fields in the record.
for (String key : d.getFieldNames()) {
log(key + " : " + d.get(key).toString());
}
// try a specific dynamic field
Object val = d.getFieldValue("e1_t");
if (val != null)
log("getting specific value: " + val.toString());
}
On Tue, Aug 30, 2011 at 2:11 AM, Michael Szalay
<[email protected]> wrote:
> Hi Juan
>
> I tried with the following code first:
>
> final SolrQuery allDocumentsQuery = new SolrQuery();
> allDocumentsQuery.setQuery("id:" + myId);
> allDocumentsQuery.setFields("*");
> allDocumentsQuery.setRows(1);
> QueryResponse response = solr.query(allDocumentsQuery, METHOD.POST);
>
>
> With this, only non-dynamic fields are returned.
> Then I wrote the following helper method:
>
> private Set<String> getDynamicFields() throws SolrServerException,
> IOException {
> final LukeRequest luke = new LukeRequest();
> luke.setShowSchema(false);
> final LukeResponse process = luke.process(solr);
> final Map<String, FieldInfo> fieldInfo = process.getFieldInfo();
> final Set<String> dynamicFields = new HashSet<String>();
> for (final String key : fieldInfo.keySet()) {
> if (key.endsWith("_string") || (key.endsWith("_dateTime"))) {
> dynamicFields.add(key);
> }
> }
> return dynamicFields;
> }
>
> where as _string and _dateTime are the suffixes of my dynamic fields.
> This one returns really all stored fields of the document:
>
> final Set<String> dynamicFields = getDynamicFields();
> final SolrQuery allDocumentsQuery = new SolrQuery();
> allDocumentsQuery.setQuery("uri:" + myId);
> allDocumentsQuery.setFields("*");
> for (final String df : dynamicFields) {
> allDocumentsQuery.addField(df);
> }
>
> allDocumentsQuery.setRows(1);
> QueryResponse response = solr.query(allDocumentsQuery, METHOD.POST);
>
> Is there a more elegant way to do this? We are using solrj 3.1.0 and solr
> 3.1.0.
>
> Regards
> Michael
> --
> Michael Szalay
> Senior Software Engineer
>
> basis06 AG, Birkenweg 61, CH-3013 Bern - Fon +41 31 311 32 22
> http://www.basis06.ch - source of smart business
>
> ----- Ursprüngliche Mail -----
> Von: "Juan Grande" <[email protected]>
> An: [email protected]
> Gesendet: Montag, 29. August 2011 18:19:05
> Betreff: Re: How to list all dynamic fields of a document using solrj?
>
> Hi Michael,
>
> It's supposed to work. Can we see a snippet of the code you're using to
> retrieve the fields?
>
> *Juan*
>
>
>
> On Mon, Aug 29, 2011 at 8:33 AM, Michael Szalay
> <[email protected]>wrote:
>
>> Hi all
>>
>> how can I list all dynamic fields and their values of a document using
>> solrj?
>> The dynamic fields are never returned when I use setFields(*).
>>
>> Thanks
>>
>> Michael
>>
>> --
>> Michael Szalay
>> Senior Software Engineer
>>
>> basis06 AG, Birkenweg 61, CH-3013 Bern - Fon +41 31 311 32 22
>> http://www.basis06.ch - source of smart business
>>
>>
>