Reactive Elasticsearch Operations
ReactiveElasticsearchOperations
是使用 ReactiveElasticsearchClient
对 Elasticsearch 集群执行高级命令的网关。
ReactiveElasticsearchOperations
is the gateway to executing high level commands against an Elasticsearch cluster using the ReactiveElasticsearchClient
.
ReactiveElasticsearchTemplate
是 ReactiveElasticsearchOperations
的默认实现。
The ReactiveElasticsearchTemplate
is the default implementation of ReactiveElasticsearchOperations
.
要开始,`ReactiveElasticsearchOperations`需要了解与之一起工作的实际客户端。有关客户端及其配置方式的详细信息,请参阅Reactive Rest Client。
To get started the ReactiveElasticsearchOperations
needs to know about the actual client to work with.
Please see Reactive Rest Client for details on the client and how to configure it.
Reactive Operations Usage
ReactiveElasticsearchOperations
可用于保存、查找和删除域对象,并将这些对象映射到存储在 Elasticsearch 中的文档。
ReactiveElasticsearchOperations
lets you save, find and delete your domain objects and map those objects to documents stored in Elasticsearch.
考虑以下事项:
Consider the following:
@Document(indexName = "marvel")
public class Person {
private @Id String id;
private String name;
private int age;
// Getter/Setter omitted...
}
ReactiveElasticsearchOperations operations;
// ...
operations.save(new Person("Bruce Banner", 42)) 1
.doOnNext(System.out::println)
.flatMap(person -> operations.get(person.id, Person.class)) 2
.doOnNext(System.out::println)
.flatMap(person -> operations.delete(person)) 3
.doOnNext(System.out::println)
.flatMap(id -> operations.count(Person.class)) 4
.doOnNext(System.out::println)
.subscribe(); 5
上述输出在控制台上输出以下序列。
The above outputs the following sequence on the console.
> Person(id=QjWCWWcBXiLAnp77ksfR, name=Bruce Banner, age=42)
> Person(id=QjWCWWcBXiLAnp77ksfR, name=Bruce Banner, age=42)
> QjWCWWcBXiLAnp77ksfR
> 0
1 | Insert a new Person document into the marvel index . The id is generated on server side and set into the instance returned. |
2 | Lookup the Person with matching id in the marvel index. |
3 | Delete the Person with matching id , extracted from the given instance, in the marvel index. |
4 | Count the total number of documents in the marvel index. |
5 | Don’t forget to subscribe(). |