4

Let me take an example to explain the scenario. Suppose i have data indexed to Solr as :

{
 "id" : "872919092",
 "filename" : "science_book",
 "path" : "/local/abc/"
}

Now i want to modify the data already indexed to Solr with id : 872919092. I need to change the filename : science_book with filename : history_book and add new attribute topic : mughal to the same indexed data keeping path unchanged. I do not want to pass the path again as there is no change in that and already indexed to Solr. According to the documentation of Solr this is possible. How do i do that using nodejs solr-client update method? I want to achieve the below scene :

  1. If the attribute does not exist in the Solr indexed data with particular id, add that to the already indexed data keeping the previously indexed data unchanged.
  2. If the attribute already exists in the Solr indexed data with particular id, change the value of the previously indexed attribute keeping the other indexed data unchanged.

I am passing the data to add in Solr as a hash which is a combination of only the new attributes to be added to already indexed data in Solr and changes in the value of the previously indexed data to Solr.

Note : I am using Solr-4.3.0 and node module solr-client for adding data to Solr.

4

1 回答 1

3

您将需要添加 set 或 add 到字段并删除其余字段。您需要 id 和字段。

var doc = {
   "id" : "872919092",
   filename : {"set" : "history_book"},
   topic : {"add" : "mughal"}
}

client.add(doc)

另请注意,您可以使用 inc 或 dec 递增或递减 int

于 2013-07-19T00:04:14.173 回答