ES
什么是ES文档操作:
1.ES(document oriented)(document)(index)ES
GET _search
DSLDSL
ES
Node:
master Node:,
data node:, crud
client node:
1- 在生产环境下,如果不修改ElasticSearch节点的角色信息,在高数据量,高并发的场景下集群容易出现脑裂等问题
23masternode.master: true node.data: false
3datanode.master: false node.data: true
4clientnode.master: false node.data: true
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
<version>5.2.2</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.7</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.7</version>
</dependency>
Settings settings = Settings.builder()
.put("client.transport.sniff", true).build();
TransportClient client = new PreBuiltTransportClient(settings);
import static org.elasticsearch.common.xcontent.XContentFactory.*;
IndexResponse response = client.prepareIndex("crm", "vip", "1")
.setSource(jsonDataText).get();
GetResponse response = client.prepareGet("crm", "vip", "1").get();
client.prepareUpdate("crm", "vip", "1").setDoc("{\"sex\":0}").get();
client.prepareUpdate("crm", "vip", "1")
.setScript(new Script("ctx._source.sex = 1" , ScriptService.ScriptType.INLINE,null, null))
.get();
IndexRequest indexRequest = new IndexRequest("crm", "vip", "1")
.source(originalJsonData);
UpdateRequest updateRequest = new UpdateRequest("crm", "vip", "1")
.doc(updateJsonData).upsert(indexRequest);
client.update(updateRequest).get();
DeleteResponse response = client.prepareDelete("crm", "vip", "1").get();
BulkRequestBuilder bulkRequest = client.prepareBulk();
bulkRequest.add(client.prepareIndex("crm", "vip", "1")
.setSource(vip1JsonData));
bulkRequest.add(client.prepareIndex("crm", "vip", "2")
.setSource(vip2JsonData));
BulkResponse bulkResponse = bulkRequest.get();
来源:博客园
作者:悠悠紫荆
链接:https://www.cnblogs.com/1999wang/p/11517626.html