From here, an example of how to query something IN
a list, but the example is idealized. It queries id
.
I want to do a query: name in ["abc","ghi"]
From here, I find an answer, but I find it not work.
I try several different ways below.
@Query("{ \"terms\": {\"name\": [\"?0\"] } }") //the 1st query.
Flux<Response> findByNames(String names);
@Query("{\"names\": {\"values\": ?0 }}") //mimic the ids query in the example.
Flux<Response> findByNames(List<String> names);
@Query("{ \"terms\": {\"name\": ?0 } }")
Flux<Response> findByNames(List<String> names);
The 1st query, I pass in nameList.stream().collect(Collectors.joining(","))
, it generates the query json is nearly correct, but a slight error:
{ "terms": {"name": ["abc,ghi"] } }
If it can generate the query json like ( look at the quote mark):
{ "terms": {"name": ["abc","ghi"] } }
then, it works.
So, My question is: How to do a terms query on the @Query in SpringBoot Elasticsearch Repository