ElasticSearch for Modify your Data

一、Updating Documents

This example shows how to update our previous document (ID of 1) by changing the name field to "Jane Doe":

curl -XPOST ‘192.168.56.101:9200/customer/external/1/_update?pretty‘ -d ‘

{

"doc":{"name":"Jane Doe"}

}‘

This example shows how to update our previous document (ID of 1) by changing the name field to "Jane Doe" and at the same time add an age field to it:

curl -XPOST ‘192.168.56.101:9200/customer/external/1/_update?pretty‘ -d ‘

{

"doc":{"name":"Jane Doe","ages":20}

0}‘

Elasticsearch支持通过脚本修改文档信息

curl -XPOST ‘192.168.56.101:9200/customer/external/1/_update?pretty‘ -d ‘
{
 "script" : "ctx._source.ages += 5"
}‘

OR

curl -XPOST ‘192.168.56.101:9200/customer/external/1/_update?pretty‘ -d ‘

{

"script": {

"inline":{ctx._source.ages+=age},

"params":{

"age":20

}

}

}‘

除了_source字段,可以通过ctx来获得_index、_type、_id、_version、_parent、_timestamp、_ttl等字段信息

也可以利用srcipt添加字段信息

curl -XPOST ‘192.168.56.101:9200/customer/external/1/_update?pretty‘ -d  ‘

{

"script":"ctx._source.name_of_new_field=\"value_of_new_field\""

}‘

也可以利用srcipt移除字段信息

curl -XPOST ‘192.168.56.101:9200/customer/external/1/_update?pretty‘ -d ‘

{

"script":"ctx._source.remove(\"name_of_field\")"

}‘

二、Delting Documents

Deleting a document is fairly straightforward. This example shows how to delete our previous customer with the ID of 2

curl -XDELETE ‘192.168.56.101:9200/customer/external/2?pretty‘

三、Batch Processing

As a quick example, the following call indexes two documents (ID 1 - John Doe and ID 2 - Jane Doe) in one bulk operation:

curl -XPOST ‘localhost:9200/customer/external/_bulk?pretty‘ -d ‘
{"index":{"_id":"1"}}
{"name": "John Doe" }
{"index":{"_id":"2"}}
{"name": "Jane Doe" }
‘

This example updates the first document (ID of 1) and then deletes the second document (ID of 2) in one bulk operation:

curl -XPOST ‘localhost:9200/customer/external/_bulk?pretty‘ -d ‘
{"update":{"_id":"1"}}
{"doc": { "name": "John Doe becomes Jane Doe" } }
{"delete":{"_id":"2"}}
时间: 2024-11-05 18:45:15

ElasticSearch for Modify your Data的相关文章

(error) MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk. Commands that may modify the data set are disabled. Please check Redis logs for details about t

运行redis过程中,突然报错如下: (error) MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk. Commands that may modify the data set are disabled. Please check Redis logs for details about the error. 解决方案(百度到的答案,不过确实有用):

MISCONF Redis is configured to save RDB snapshots, but it is currently not able to persist on disk. Commands that may modify the data set are disabled, because this instance is configured to report e

早上来到公司,线上的项目报错: Error in execution; nested exception is io.lettuce.core.RedisCommandExecutionException: MISCONF Redis is configured to save RDB snapshots, but it is currently not able to persist on disk. Commands that may modify the data set are disa

Elasticsearch master node、 data node、 client node的区别与各自特点

es集群里的master node.data node和client node到底是怎么个意思,分别有何特点? master节点 主要功能是维护元数据,管理集群各个节点的状态,数据的导入和查询都不会走master节点,所以master节点的压力相对较小,因此master节点的内存分配也可以相对少些:但是master节点是最重要的,如果master节点挂了或者发生脑裂了,你的元数据就会发生混乱,那样你集群里的全部数据可能会发生丢失,所以一定要保证master节点的稳定性. data node 是负

ElasticSearch 中 master、data 和 client 节点

在生产环境下,如果不修改elasticsearch节点的角色信息,在高数据量,高并发的场景下集群容易出现脑裂等问题. 默认情况下,elasticsearch 集群中每个节点都有成为主节点的资格,也都存储数据,还可以提供查询服务.这些功能是由两个属性控制的. 1. node.master 2. node.data 默认情况下这两个属性的值都是true. node.master:这个属性表示节点是否具有成为主节点的资格 注意:此属性的值为 true,并不意味着这个节点就是主节点.因为真正的主节点,是

elasticsearch之hello(spring data整合)

1.书写pom.xml文件 <dependencies> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-elasticsearch</artifactId> <version>2.0.4.RELEASE</version> </dependency> <dependency>

C# Web API Modify Post Data Size Limit

在Web.config中增加下面两个配置后,重启IIS即可. 1.修改http请求数据大小限制 <system.web>  <httpRuntime maxRequestLength="50000000" /></system.web> 2.如果数据序列化格式为Json,请增加: <system.web.extensions> <scripting> <webServices> <jsonSerializat

使用JAVA操作ElasticSearch(Java API 和Spring Data ElasticSearch)

Java API 我的ElasticSearch集群的版本是6.2.4,导入elasticsearch相关的maven依赖也是6.2.4,不同版本的api可能会有差异 一:maven依赖 <!--elasticsearch核心依赖--> <dependency> <groupId>org.elasticsearch</groupId> <artifactId>elasticsearch</artifactId> <version

Spring Data ElasticSearch的使用十个小案例

1.什么是Spring Data Spring Data是一个用于简化数据库访问,并支持云服务的开源框架.其主要目标是使得对数据的访问变得方便快捷,并支持map-reduce框架和云计算数据服务. Spring Data可以极大的简化JPA的写法,可以在几乎不用写实现的情况下,实现对数据的访问和操作.除了CRUD外,还包括如分页.排序等一些常用的功能. 2.什么是Spring Data ElasticSearch Spring Data ElasticSearch 基于 spring data

Spring Data ElasticSearch的使用

1.什么是Spring Data Spring Data是一个用于简化数据库访问,并支持云服务的开源框架.其主要目标是使得对数据的访问变得方便快捷,并支持map-reduce框架和云计算数据服务. Spring Data可以极大的简化JPA的写法,可以在几乎不用写实现的情况下,实现对数据的访问和操作.除了CRUD外,还包括如分页.排序等一些常用的功能. 2.什么是Spring Data ElasticSearch Spring Data ElasticSearch 基于 spring data