使用节点模块 solr-client 向 Solr-4.3.0 添加和更新数据 [英] Add and update data to Solr-4.3.0 using node module solr-client

查看:62
本文介绍了使用节点模块 solr-client 向 Solr-4.3.0 添加和更新数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我举个例子来解释这个场景.假设我将数据索引到 Solr 为:

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/"
}

现在我想修改已经用 id : 872919092 索引到 Solr 的数据.我需要使用 filename : history_book 更改 filename : science_book 并将新属性 topic : mughal 添加到保持 path 的相同索引数据 不变.我不想再次传递 path ,因为它没有变化并且已经索引到 Solr.根据 Solr 的文档这个有可能.我如何使用 nodejs solr-client update方法?我想实现以下场景:

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. 如果具有特定 id 的 Solr 索引数据中不存在该属性,则将其添加到已索引数据中,保持先前索引数据不变.
  2. 如果该属性已存在于具有特定 id 的 Solr 索引数据中,则更改先前索引属性的值,保持其他索引数据不变.

我将要添加到 Solr 中的数据作为散列传递,它是仅添加到 Solr 中已编入索引的数据的新属性和先前编入索引的数据值更改给 Solr 的组合.

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.

注意:我正在使用 Solr-4.3.0 和节点模块 solr-client 向 Solr 添加数据.

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

推荐答案

您需要向字段添加 set 或 add 并删除其余字段.您需要 id 和字段.

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)

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

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

这篇关于使用节点模块 solr-client 向 Solr-4.3.0 添加和更新数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆