This version is still in development and is not considered stable yet. For the latest stable version, please use Spring Data Elasticsearch 5.4.0! |
Reactive Elasticsearch Operations
ReactiveElasticsearchOperations
is the gateway to executing high level commands against an Elasticsearch cluster using the ReactiveElasticsearchClient
.
The ReactiveElasticsearchTemplate
is the default implementation of ReactiveElasticsearchOperations
.
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
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(). |