You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Michael Szalay <mi...@basis06.ch> on 2011/08/29 13:33:44 UTC

How to list all dynamic fields of a document using solrj?

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 


Re: How to list all dynamic fields of a document using solrj?

Posted by Erick Erickson <er...@gmail.com>.
Sure, just use the Luke handler. See LukeRequest and LukeResponse
in the API documentation.

Best
Erick

On Wed, Aug 31, 2011 at 2:23 AM, Michael Szalay
<mi...@basis06.ch> wrote:
> You are right, they are not stored...
> But I is possible to see them, as the schema browser in the admin application does?
>
> 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: "Erick Erickson" <er...@gmail.com>
> An: solr-user@lucene.apache.org
> Gesendet: Dienstag, 30. August 2011 16:31:05
> Betreff: Re: How to list all dynamic fields of a document using solrj?
>
> 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
> <mi...@basis06.ch> 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" <ju...@gmail.com>
>> An: solr-user@lucene.apache.org
>> 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
>> <mi...@basis06.ch>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
>>>
>>>
>>
>

Re: How to list all dynamic fields of a document using solrj?

Posted by Michael Szalay <mi...@basis06.ch>.
You are right, they are not stored...
But I is possible to see them, as the schema browser in the admin application does?

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: "Erick Erickson" <er...@gmail.com>
An: solr-user@lucene.apache.org
Gesendet: Dienstag, 30. August 2011 16:31:05
Betreff: Re: How to list all dynamic fields of a document using solrj?

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
<mi...@basis06.ch> 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" <ju...@gmail.com>
> An: solr-user@lucene.apache.org
> 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
> <mi...@basis06.ch>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
>>
>>
>

Re: How to list all dynamic fields of a document using solrj?

Posted by Erick Erickson <er...@gmail.com>.
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
<mi...@basis06.ch> 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" <ju...@gmail.com>
> An: solr-user@lucene.apache.org
> 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
> <mi...@basis06.ch>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
>>
>>
>

Re: How to list all dynamic fields of a document using solrj?

Posted by Michael Szalay <mi...@basis06.ch>.
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" <ju...@gmail.com>
An: solr-user@lucene.apache.org
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
<mi...@basis06.ch>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
>
>

Re: How to list all dynamic fields of a document using solrj?

Posted by Juan Grande <ju...@gmail.com>.
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
<mi...@basis06.ch>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
>
>