5

In Solr, if we have a field in the schema with stored="true", and we change the analyzer associated with that field, is it possible to update just this field without reindexing all the documents? Could this be done using the "stored" values of the field with the new analyzer without going back to the original data source?

Matthew Simoneau
  • 6,199
  • 6
  • 35
  • 46
Juampa
  • 154
  • 1
  • 7
  • This seems similar to [this](http://stackoverflow.com/questions/9105542/customizing-analyzers-in-solr/9107815#comment11455477_9107815) . – RoiG Feb 03 '12 at 07:31

3 Answers3

1

Guy, I optimized your code.

    ...
    while (iter.hasNext()) {
        ...
        //server.deleteById(id) ;
        //server.commit() ;

        Collection<SolrInputDocument> docs = new ArrayList<SolrInputDocument>();
        docs.add(inputdoc) ;
        server.add(docs) ;
        // server.commit() ;
    }
    server.commit() ;
aaashun
  • 11
  • 1
0

I found a way using SolrJ.

        SolrQuery query = new SolrQuery();

        query.setQuery( "whatever_by_id" );

        QueryResponse rsp;

        rsp = server.query(query);

        Iterator<SolrDocument> iter = rsp.getResults().iterator();

        while (iter.hasNext()) {
            SolrDocument resultDoc = iter.next();
            String id = (String) resultDoc.getFieldValue("oid"); //id is the uniqueKey field

            SolrInputDocument inputdoc = new SolrInputDocument() ;
            for( Map.Entry<String, Object> f : resultDoc.entrySet()) {
                inputdoc.setField(f.getKey(), f.getValue()) ;
            }

            server.deleteById(id) ;
            server.commit() ;

            Collection<SolrInputDocument> docs = new ArrayList<SolrInputDocument>();
            docs.add(inputdoc) ;
            server.add(docs) ;

            server.commit() ;
        }

When we add the "new" inputdoc (a copy of the old resultDoc), it uses the new analyzer we have changed in the schema to index. It´s not very elegant, but it works.

Juampa
  • 154
  • 1
  • 7
  • Yes xD, but not all the documents. First full-import took 8 hours and I do not want to repeat it xD. – Juampa Oct 28 '10 at 19:15
0

check out this IBM Tutorial for Solr

Kuntal Basu
  • 830
  • 2
  • 12
  • 28