Is there any example of using Spring Reactive to read through all documents of an ElasticSearch index? - reactive-programming

Is there any example of using Spring Reactive to read through all documents of an ElasticSearch index?
I want to avoid Reactive repository though.

If you have an entity Entity and have a ReactiveElasticsearchOperations autowired then
Flux<SearchHit<Entity>> flux = operations.search(Query.findAll(), Entity.class);
and just consume the flux.

Related

Can I split data into 2 collections in Mongo DB and access the same in SpringBoot

I am using Mongo DB as Database for my springboot application.
I wanted to split the data into 2 collections -primary and auxillary just like how we do it in sql- priamary and secondary table.
Can i do the above and use them in my Springboot application??
Spring boot + Spring data mongo supports multiple collections out of the box.
Just create your POJOs and add the #Document annotation.
You can then define Repository classes (extends MongoRepository) that are then bound to each collection.
Use them to perform nearly any actions on the data.
If you want the data to be in multiple databases, that is also possible, just a bit more complicated.

Multitenancy with Spring Data and Mongo

I am developing a SaaS application with Spring data and Mongo data with multitenancy on the schema level. So, separation is done on each collection. Each collection has tenant_id.
I managed to implement with Mongo template plus query but in that case, I lose repository abstraction.
What I can not find is how to extend repositories and use all the functions from repository API and add for each query type (find, save, update..) tenant_id in the query?

Specify raw aggregate request with Spring Data Mongodb

I write a big aggregate query for mongodb, now I try to translate it in Spring Data Mongodb API, and it's very complicated, and spring data api did not help me a lot.
So like with #Query annotation, is it possible to just specify my raw aggregate query in text and map my field with Spring Data (or just Mongodb Java driver) ?
I won't c/p my aggregate request because, it's not the purpose of my question.
I found a solution by using MongoDB java driver, which is available through Spring Data :
DBCollection collection = mongoTemplate.getCollection("myCollection");
and I used BasicDBObject from this solution : MongoDB aggregation with Java driver

Do a MongoDB update with Spring XD & Spring Integration

I'm trying to read a file with Spring XD (source), modify data (processor) and save it in Mongo (sink). I've used the default MongoDB sink which do a save and expect a Spring Data Mongo entity.
But I'd like to do an update with upsert. How can I do ?
Thanks.
The mongo outbound adapter uses MongoTemplate.save() which is already an upsert according to the javadoc.
If you provide your own ObjectId for the same object it will update. You can for example do this during your processor.

#DbRef is not saving child object automatically in spring data mongodb

I am currently using GA release of Spring Data MongoDB framework and #DbRef is not saving child object automatically in spring data mongodb. Can you tell me how can i make it work?
Saving child objects is not built into Spring Data MongoDB so you have to do it manually or you can extend AbstractMongoEventListener as I described it in my article: Spring Data MongoDB cascade save on DBRef objects