Spring boot with ElasticsearchRepository and RestHighLevelClient parameters query - spring

I'm using Spring Boot with ElasticsearchRepository and RestHighLevelClient. I have this query in mt repository class:
public interface BillingCycleRepository extends ElasticsearchRepository<BillingCycle, String> {
List<BillingCycle> findByUserIdOrderByStartDateDesc(String userId);
}
In my console, I can see this:
org.elasticsearch.client.RestClient : request [POST http://localhost:9200/dev-billing-cycle/_doc/_search?rest_total_hits_as_int=true&typed_keys=true&ignore_unavailable=false&expand_wildcards=open&allow_no_indices=true&ignore_throttled=true&search_type=query_then_fetch&batched_reduce_size=512]
It generates a lot of parameters, like rest_total_hits_as_int and `typed_keys.
Is it possible to configure these parameters and add any others, like "filter_path", "preference"?

Related

Using Vertx with spring-data-neo4j outside Spring container

We have DAO layer which uses Spring data to communicate with Neo4j. Inside DAO layer, it uses the spring annotations #Autowired, #Repository etc. We have API Layer which is written in Vertx. DAO layer is used as a library inside the Vertx application. I am able to use #Inject to inject Models with help of Guice. However, the code block like personDo.findByName('test') fails because it is not able to connect to neo4j outside of spring env. Any suggestions or pointer on how to use spring data without spring application?
DAO layer
// PersonDao.java
#Repository
public interface PersonDao extends CustomerDaoCustom, BaseDao<CustomerDo> {
Optional<PersonDo> findByName(String name);
}
Vertx Application:
import com.example.dao.PersonDao;
import com.example.models.PersonDo;
...
#Inject
private PersonDao personDao;
...
public void findPerson(ServiceRequest request, Handler<AsyncResult<ServiceResponse>> resultHandler) {
String personName = "Sam";
logger.info("Example: finding person with name={}", personName);
Optional<PersonDO> personOpt = personDao.findByName(personName);
personOpt.ifPresentOrElse(person -> {
logger.info("\t Person found: {}", person);
logger.info("\t Person UUID: {}", person.getUuid());
logger.info("\t Details: {}", person.dump());
}, () -> logger.info("\t Person with name={} not found", personName));
personDao is null instead of org.springframework.data.neo4j.repository.query.SimpleQueryByExampleExecutor#379ce046
This can be achieved easily in API if I use the spring boot application to start my vertx service but I am trying not to use Spring boot in my API layer.

Spring boot pageable is not working with where clause

I tried to use spring pageable with Where clause and containing but it returns nothing.
My Spring version : 2.1.4.RELEASE
Database : MySql
public interface ItemRepository extends JpaRepository<ItemEntity, String> {
List<ItemEntity> findByCodeIgnoreCaseContainingAndNameIgnoreCaseContaining(String code, String name);
}
Either Change the JPA Query as below :
Page<User> findByCodeIgnoreCaseContainingAndNameIgnoreCaseContaining(String code, String name,Pageable pageable);
Or use PagingAndSortingRepository instead of JpaRepository.
Please refer https://www.baeldung.com/spring-data-jpa-pagination-sorting

Can we use CrudRepository and ReactiveCrudRepository simaultaneously in the application

I am using couchbase in my springboot application and using both ReactiveCrudRepository and CrudRepository separately. But while using CrudRepository method it is throwing me the following error
"reactor.core.publisher.MonoOnAssembly cannot be cast to my POJO
You can use it in the same project but they have to be different classes and implement different interfaces.
Synchronous Repository:
public interface UserEntityRepository extends
CouchbasePagingAndSortingRepository<UserEntity, String> {
}
Async Repository:
public interface ReactiveUserEventRepository extends
ReactiveCouchbaseSortingRepository<UserEventEntity, String> {
}
There is a big tutorial talking about it here: https://docs.couchbase.com/tutorials/profile-store/java.html#storing-user-events

Is it possible to get request param in SPEL in Spring Data Rest?

I have simple rest repository:
TestRepository extends MongoRepository<Test, String> {
#PreAuthorize("#helper.hasPermissionToProjection(#projection)")
#Override
Page<Test> findAll(Pageable pageable);
}
What I need is to pass projection param from the link api/tests?projection=full to my bean's hasPermissionToProjection method.
Is it possible to do like that?

spring boot multiple mongodb datasource

We are using spring boot and we have multiple mongodbs within the system. We are able to configure "one" mongodb in application.properties files, as per the spring boot documents. Now we have a need to write to multiple mongodbs. How can we configure this?
Hope someone can help and any code examples would be helpful.
Thanks
GM
Use multiple #Bean methods, where you create and configure your datasources, and specify the bean name to distinguish them.
Example:
#Bean("primary")
public Mongo primaryMongo() throws UnknownHostException {
Mongo mongo = new Mongo();
// configure the client ...
return mongo;
}
#Bean("secondary")
public Mongo secondaryMongo() throws UnknownHostException {
Mongo mongo = new Mongo();
// configure the client ...
return mongo;
}
When you want to access the datasource, use the #Qualifier annotation on the field to specify the datasource with the bean name:
#Autowired
#Qualifier("primary")
private Mongo mongo;

Resources