本文主要是指利用solr界面或cul的更新solr的值。如果需要代码中单值更新请参考黎明露珠的博客链接:http://www.cnblogs.com/limingluzhu/p/5535314.html,我在文章的最末也给出了代码单值更新的示例。

在实际的研发过程中,为方便测试往往需要更改solr字段值,但是除了依赖程序的更新solr本身界面是否支持我们进行solr字段的值更新呢 ,答案是肯定支持的 。

详细方法请参考连接:http://yonik.com/solr/atomic-updates/

实际就是我们solr   query的documents:

其示例documents 修改值方法如下 :

    {
"ADDRESSID": "89fe3cffd70311e681c8fa163ea75434",
"MEMBERTYPE": {
"set": "1"
}
}

我这的 示例是json类型的,但是原理都一样的 。

这里的commit,可以理解为一个拼装起来的 get请求.当然你也可以用curl来直接请求。具体示例便是下文的curl请求。

关于具体语法问题原文如下:

Solr supports several modifiers that atomically update values of a document.

  • set – set or replace a particular value, or remove the value if null is specified as the new value
  • add – adds an additional value to a list
  • remove – removes a value (or a list of values) from a list
  • removeregex – removes from a list that match the given Java regular expression
  • inc – increments a numeric value by a specific amount (use a negative value to decrement)

具体示例原文如下:

Update Modifier Example

First, let’s add a document representing a book:

$ curl http://localhost:8983/solr/demo/update -d '
[
{"id" : "book1",
"title_t" : "Snow Crash", // text field
"copies_i" : 5,
"cat_ss" : "Science Fiction" // multi-valued string field
}
]'

Now we can update that document, adding the author field, incrementing the number of copies we have, and adding an additional category:

$ curl http://localhost:8983/solr/demo/update -d '
[
{"id" : "book1",
"author_s" : {"set":"Neal Stephenson"},
"copies_i" : {"inc":3},
"cat_ss" : {"add":"Cyberpunk"}
}
]'

Now if we retrieve the document using real-time get, we will see the updated fields:

$ curl http://localhost:8983/solr/demo/get?id=book1
{
  "doc": {
    "id":"book1",
    "title_t":["Snow Crash"],
    "copies_i":8,
    "cat_ss":["Science Fiction""Cyberpunk"],
    "author_s":"Neal Stephenson",
    "_version_":1408729977723027456}}
 

And finally, remove “Cyberpunk” from the cat field:

$ curl http://localhost:8983/solr/demo/update -d '
[
{"id" : "book1",
"cat" : {"remove":"Cyberpunk"}
}
]'

Atomic Updates with SolrJ

Here is an example of how to do a partial update via Solr’s Java client, SolrJ:

// create the SolrJ client
HttpSolrClient client = new HttpSolrClient("http://localhost:8983/solr"); // create the document
SolrInputDocument sdoc = new SolrInputDocument();
sdoc.addField("id","book1");
Map<String,Object> fieldModifier = new HashMap<>(1);
fieldModifier.put("add","Cyberpunk");
sdoc.addField("cat", fieldModifier); // add the map as the field value client.add( sdoc ); // send it to the solr server client.close(); // shutdown client before we exit
 solr代码单值更新示例:
CloudSolrClient server = new CloudSolrClient(ZkHost);
server.setParser(new XMLResponseParser());
SolrInputDocument doc = new SolrInputDocument();
Map<String, String> partialUpdate = new HashMap<String, String>();
partialUpdate.put("set", memberType);
doc.addField("ADDRESSID", addressId);//主键
doc.addField("MEMBERTYPE", partialUpdate);
doc.addField("LATESTUSETIME", DateUtils.getNow());

solr 利用cul或solr界面单值更新的更多相关文章

  1. Android开发——利用Cursor+CursorAdapter实现界面实时更新

    好久没有更新博客了.不是没时间写,而是太懒.而且感觉有些东西没有时间总结,之之后再想写,就想不起来了.晚上新发现一点东西,所以就及时写下来. 最近利用业余时间在看Android的Download模块, ...

  2. Solr学习笔记---部署Solr到Tomcat上,可视化界面的介绍和使用,Solr的基本内容介绍,SolrJ的使用

    学习Solr前需要有Lucene的基础 Lucene的一些简单用法:https://www.cnblogs.com/dddyyy/p/9842760.html 1.部署Solr到Tomcat(Wind ...

  3. 商城06——solr索引库搭建&solr搜索功能实现&图片显示问题解决

    1.   课程计划 1.搜索工程的搭建 2.linux下solr服务的搭建 3.Solrj使用测试 4.把数据库中的数据导入索引库 5.搜索功能的实现 2.   搜索工程搭建 要实现搜索功能,需要搭建 ...

  4. solr课程学习系列-solr服务器配置(2)

    本文是solr课程学习系列的第2个课程,对solr基础知识不是很了解的请查看solr课程学习系列-solr的概念与结构(1) 本文以windows的solr6服务器搭建为例. 一.solr的工作环境: ...

  5. Solr 01 - 什么是Solr + Solr安装包目录结构说明

    目录 1 Solr概述 1.1 Solr是什么 1.2 Solr与Lucene的区别 2 Solr文件说明 2.1 Solr的目录结构 2.2 其他常用概念说明 2.3 创建基础文件目录 2.4 so ...

  6. Solr系列六:solr搜索详解优化查询结果(分面搜索、搜索结果高亮、查询建议、折叠展开结果、结果分组、其他搜索特性介绍)

    一.分面搜索 1. 什么是分面搜索? 分面搜索:在搜索结果的基础上进行按指定维度的统计,以展示搜索结果的另一面信息.类似于SQL语句的group by 分面搜索的示例: http://localhos ...

  7. Solr系列四:Solr(solrj 、索引API 、 结构化数据导入)

    一.SolrJ介绍 1. SolrJ是什么? Solr提供的用于JAVA应用中访问solr服务API的客户端jar.在我们的应用中引入solrj: <dependency> <gro ...

  8. Solr系列三:solr索引详解(Schema介绍、字段定义详解、Schema API 介绍)

    一.Schema介绍 1. Schema 是什么? Schema:模式,是集合/内核中字段的定义,让solr知道集合/内核包含哪些字段.字段的数据类型.字段该索引存储. 2. Schema 的定义方式 ...

  9. Solr系列一:Solr(Solr介绍、Solr应用架构、Solr安装使用)

    一.前言 前面已经学习了Lucene的分词.索引详解.搜索详解的知识,已经知道开发一个搜索引擎的流程了.现在就会有这样的一个问题:如果其他的系统也需要使用开发的搜索引擎怎么办呢?这个时候就需要把开发的 ...

随机推荐

  1. 临界区(Critical Section)的封装和使用示例

    向我老大致敬! 这个做法其实是抄我老大的.服务器中,多线程经常需要使用临界区,为了简化代码的使用,把临界区封装为 CThreadLockHandle  类,通过封装,使用临界区资源每次只需要一行代码, ...

  2. MFC绘图相关GDI工具对象和函数介绍

    在利用MFC进行界面编程时,除了需要熟悉各种类型控件的操作外,还会经常遇到图形绘制和显示的问题,比如时频分析界面.图像处理界面等.处理这些软件界面开发问题时,不可避免地需要用到一系列GDI工具对象和相 ...

  3. Sql server 打不开了,无法识别的配置节 system.serviceModel 解决方案

    异常描述: System.Configuration.ConfigurationErrorsException: 配置系统未能初始化 ---> System.Configuration.Conf ...

  4. 【BZOJ】2021: [Usaco2010 Jan]Cheese Towers(dp)

    http://www.lydsy.com/JudgeOnline/problem.php?id=2021 噗,自己太弱想不到. 原来是2次背包. 由于只要有一个大于k的高度的,而且这个必须放在最顶,那 ...

  5. java读取配置文件(转)

    转载:http://blog.csdn.net/gaogaoshan/article/details/8605887 java 4种方式读取配置文件 + 修改配置文件     方式一:采用Servle ...

  6. db2 设置表 not null

    db2将原表列notnull属性修改为null属性的方法   今天把自己遇到的一个小问题跟大家分享一下如何修改db2数据库表中列的属性--将列的非空属性改为允许空的属性,修改数据表的某一列属性其实很简 ...

  7. java ssh介绍(1)

    今年我一直在思考web开发里的前后端分离的问题,到了现在也颇有点心得了,随着这个问题的深入,再加以现在公司很多web项目的控制层的技术框架由struts2迁移到springMVC,我突然有了一个新的疑 ...

  8. retrival and clustering : week 3 k-means 笔记

    华盛顿大学 machine learning 笔记. K-means algorithm 算法步骤: 0. 初始化几个聚类中心 (cluster centers)μ1,μ2, … , μk 1. 将所 ...

  9. linux软件的安装和卸载

    http://blog.chinaunix.net/uid-25572546-id-1995028.html

  10. JavaScript------一元运算符+的使用

    var y = "5"; // y 是一个字符串 var x = + y; // x 是一个数字 var y = "John"; // y 是一个字符串 var ...