Is it possible to change the analyzer specified in the schema in Solr without reindexing from the original source?

故事扮演 提交于 2019-11-27 18:43:52

问题


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?


回答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() ;



回答2:


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.




回答3:


check out this IBM Tutorial for Solr



来源:https://stackoverflow.com/questions/4037625/is-it-possible-to-change-the-analyzer-specified-in-the-schema-in-solr-without-re

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!