如何更新Apache Solr文档中的字段?

时间:2018-11-27 12:06:41

标签: java apache solr

我正在尝试以下代码来更新Apache Solr中的字段。 但这正在文档中创建新记录。

公共无效消费(字符串消息)引发SolrServerException,IOException {

    System.out.println(message);

    Product product = new ObjectMapper().readValue(message, Product.class);


    //Preparing the Solr client 
      String urlString = "http://localhost:8983/solr/product";
      SolrClient solrClient = new HttpSolrClient.Builder(urlString).build();   

      UpdateRequest updateRequest = new UpdateRequest();
      updateRequest.setAction(UpdateRequest.ACTION.COMMIT, false, false);  

      SolrInputDocument myDocumentInstantlycommited = new SolrInputDocument();
      myDocumentInstantlycommited.setField("product_id", "42424");
      myDocumentInstantlycommited.setField("Price", "566666");

      updateRequest.add( myDocumentInstantlycommited);
      UpdateResponse rsp = updateRequest.process(solrClient); 
      System.out.println("Documents Updated");
      System.out.println(rsp.getResponse());
}

在这种情况下,我试图将具有product_id的Price字段更新为42424,但是它将其替换为新记录。 谢谢,

0 个答案:

没有答案