Add and update data to Solr-4.3.0 using node modul

2019-05-07 12:23发布

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.

1条回答
三岁会撩人
2楼-- · 2019-05-07 12:50

You will need to add set or add to the field and remove the rest of the fields. You need id and the fields.

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

client.add(doc)

Also note that you can increment or decrement int's using inc or dec

查看更多
登录 后发表回答