本文主要是指利用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. pl/sql 实例解析 01

    1. 合并 firstname, lastname. 1: declare 2: v_first_name varchar2(255); 3: v_last_name varchar2(255); 4 ...

  2. SQL语句教程

    SQL指令 SELECT DISTINCT WHERE AND OR IN BETWEEN LIKE ORDER BY 函数 COUNT GROUP BY HAVING ALIAS 表格链接 外部链接 ...

  3. List、Map、Set三个接口存储元素时各有什么特点?

    List.Map.Set三个接口存储元素时各有什么特点? 解答: 1)List是有序的Collection,使用此接口能够精确的控制每个元素插入的位置.用户能够使用索引(元素在List中的位置,类似于 ...

  4. 开启GitHub模式,now!

    (原文地址为:http://www.karottc.com/blog/2014/06/15/current-doing/) 最近看到了一篇文章,该文章的作者将自己连续177天在github上commi ...

  5. uva414 - Machined Surfaces

    uva414 - Machined Surfaces /* 水题,值得一提的是,getline使用时注意不能让它多吃回车键,处理方法可以用getchar. */ #include <iostre ...

  6. js高级面试题

    <script> //1. var foo = { bar: function () { return this.baz; }, baz: 1 }; (function () { retu ...

  7. sizeWithFont:方法使用明细

    个人总结: Computing Metrics for a Single Line of Text– sizeWithFont: 同下面,换行方式默认取NSLineBreakByWordWrappin ...

  8. 1、Android自己的下拉刷新SwipeRefreshLayout

    <android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/ ...

  9. CSS3的自定义字体@font-face:将图片ICON转为字体

    大家都知道现在各个浏览器都支持CSS3的自定义字体(@font-face),包括IE6都支持,只是各自对字体文件格式的支持不太一样.那么对于网站中用到的各种icon,我们就可以尝试使用font来实现, ...

  10. linux时间格式化

    echo `date +'[%Y-%m-%d %H:%M:%S]'`