0

I am trying to communicate with an external web service (Elastic search API) using java, but without using any elasticsearch library, so I created a query class that match the request that we gonna send to elsaticsearch API :

GET /_search
{
  "query": {
    "multi_match" : {
      "query":    "this is a test", 
      "fields": [ "subject", "message" ] 
    }
  }
}

here is the equivalant class :

@Data
class QueryRequest{
   private Query query;
}

@Data
class Query{
   private Match multi_match;
}

@Data
class Match{
   private String query;
   private Lis<String> fields;
}

to fetch this API using curl we need to write this request :

curl --location --request GET <host> --header 'Content-Type : application/json' --data-row '{  "query": {
    "multi_match" : {
      "query":    "this is a test", 
      "fields": [ "subject", "message" ] 
    }
  }}'

my question is how I can send this kind of request using feign client

  • Actually, to serach in elastic search API you can use GET or POST, so in this case it's possible to switch for a ```@PostMapping``` with a ```@RequestBody``` : ``` @FeignClient(url=, name=) interface ESClient{ @PostMapping("/_search") Data searchData(@RequestBody RequestQuery query); } ``` NB : it's better to enable debbug mode, check this link to enable it : https://www.baeldung.com/java-feign-logging – Oussama Abouzid Aug 18 '22 at 10:28
  • possible duplicate of this [https://stackoverflow.com/questions/61083055/feign-get-request-with-body](https://stackoverflow.com/questions/61083055/feign-get-request-with-body) – Akhil Aug 18 '22 at 12:07

1 Answers1

2

I think what you are looking form is "QUERY" HTTP Method, but I'm not sure if it's fully implemented. Here is some aditional information:

IETF

https://horovits.medium.com/http-s-new-method-for-data-apis-http-query-1ff71e6f73f3

chelodegli
  • 21
  • 2