1
votes

I have a JHipster project configured with ElasticSearch and I would like to use "Request Body search" instead "URI search".

I only see the REST method : "http://localhost:8080/api/_search/address/query=*" but I would like to send a body json.

Is there a way to do this ?

Thank you !

1

1 Answers

0
votes

You can use your AddressSearchRepository which extends ElasticsearchRepository. Just write your custom queries like:

List<Address> findByStreetnameAndNumber(String streetname, int number);

It will be converted to Elasticsearch queries automatically.

If you want to use JSON payload queries, use @Query annotation and write your JSON request there, like this:

public interface AddressSearchRepository extends ElasticsearchRepository<Address, String> {
    @Query("{"bool" : {"must" : {"field" : {"name" : "?0"}}}}")
    Page<Address> findByName(String name,Pageable pageable); }

See the documentation: Spring Data Elasticsearch @Query annotation