本文主要是指利用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. 日期控件ie9失效

    WdatePicker.js在在IE 6,7,8下面多可以,就是在IE9里面无法打开. 解决方案: 方法一: $crossFrame:true做出修改.true改为false 方法二: <met ...

  2. ThinkPHP 模板 Volist 标签嵌套循环输出多维数组

    ThinkPHP 中对 volist 标签嵌套使用可实现多维数组的输出. volist 嵌套使用 一般的二维数组,可以用 volist 标签直接循环输出.对于多维数组,则需要对其中的数组成员再次使用 ...

  3. windows下搭建ffmpeg+nginx+rtmp-module搭建实时视频环境

    下载ffmpeg的Windows静态版: https://ffmpeg.zeranoe.com/builds/win64/static/下载nginx-rtmp-windows版:https://gi ...

  4. is_array

    is_array (PHP 4, PHP 5) is_array — 检测变量是否是数组

  5. 初识Python、PyCharm、Anaconda与tensorflow

    最近裸辞了,未来希望转深度学习.语音识别.文本挖掘,觉得这块特别有意思,比较好玩.开始自学相关知识,为了能够独立地.系统地了解和学习相关知识,计划不定期记录和更新一些平时的学习总结,个人关于以上几个方 ...

  6. 第一百四十二节,JavaScript,封装库--运动动画和透明度动画

    JavaScript,封装库--运动动画和透明度动画 /** yi_dong_tou_ming()方法,说明 * * yi_dong_tou_ming()方法,将一个元素,进行一下动画操作 * 1,x ...

  7. SQL Server Replace函数

    REPLACE用第三个表达式替换第一个字符串表达式中出现的所有第二个给定字符串表达式. 语法REPLACE ( 'string_expression1' , 'string_expression2' ...

  8. linux驱动开发---导出内核符号

    导出内核符号模板代码,验证小实例: /** *Copyright (c) 2013.TianYuan *All rights reserved. * *文件名称: Esdexp.c *文件标识: 导出 ...

  9. 高质量JavaScript代码

    才华横溢的Stoyan Stefanov,在他写的由O’Reilly初版的新书<JavaScript Patterns>(JavaScript模式)中,我想要是为我们的读者贡献其摘要,那会 ...

  10. MySQL设置密码的三种方法

    其设置密码有三种方法: a. ./mysqladmin -u root -p oldpassword newpasswd(记住这个命令是在/usr/local/mysql/bin中外部命令) b. S ...