aiyueqingfeng 2014-12-30
Solr4.0开始支持简单的原子更新和添加字段
Solr支持多种修饰符,自动更新文档的值。
set
– 更新一个字段add
– 添加一个字段inc
– 在原有值的基础上增加(看下面的例子更清楚)备注: 所有原始字段必须存储(在fieldType 里面设置 stored=true)
第一步、添加一条数据
$ curl http:
//localhost:8983/solr/update -H 'Content-type:application/json' -d '
[
{
"id"
:
"book1"
,
"title"
:
"Snow Crash"
,
"copies_i"
: 5,
"cat"
:
"Science Fiction"
}
]'
$ curl http:
//localhost:8983/solr/update -H 'Content-type:application/json' -d '
[
{
"id"
:
"book1"
,
"author"
: {
"set"
:
"Neal Stephenson"
},
"copies_i"
: {
"inc"
:3},
"cat"
: {
"add"
:
"Cyberpunk"
}
}
]'
$ curl http://localhost:8983/solr/get?id=book1
{
“doc”: {
“id”:”book1″,
“title”:["Snow Crash"],
“copies_i”:8,
“cat”:["Science Fiction", "Cyberpunk"],
“author”:”Neal Stephenson”,
“_version_”:1408729977723027456}}