Jua*_*mpa 5 indexing solr schema-design
在Solr中,如果我们在架构中有一个带有stored ="true"的字段,并且我们更改了与该字段关联的分析器,是否可以仅更新此字段而无需重新索引所有文档?这可以使用新分析仪使用字段的"存储"值而不返回原始数据源吗?
我找到了一种使用 SolrJ 的方法。
\n\n SolrQuery query = new SolrQuery();\n\n query.setQuery( "whatever_by_id" );\n\n QueryResponse rsp;\n\n rsp = server.query(query);\n\n Iterator<SolrDocument> iter = rsp.getResults().iterator();\n\n while (iter.hasNext()) {\n SolrDocument resultDoc = iter.next();\n String id = (String) resultDoc.getFieldValue("oid"); //id is the uniqueKey field\n\n SolrInputDocument inputdoc = new SolrInputDocument() ;\n for( Map.Entry<String, Object> f : resultDoc.entrySet()) {\n inputdoc.setField(f.getKey(), f.getValue()) ;\n }\n\n server.deleteById(id) ;\n server.commit() ;\n\n Collection<SolrInputDocument> docs = new ArrayList<SolrInputDocument>();\n docs.add(inputdoc) ;\n server.add(docs) ;\n\n server.commit() ;\n }\nRun Code Online (Sandbox Code Playgroud)\n\n当我们添加“新”inputdoc(旧 resultDoc 的副本)时,它使用我们在模式中更改的新分析器来建立索引。它\xc2\xb4s 不是很优雅,但它可以工作。
\n