如何在 Spring Data Elasticsearch 存储库中编写带有集合参数的查询注释

How to write a Query annotation with collection parameter in Spring Data Elasticsearch repository

ProductRepository extends ElasticsearchRepository<Product, String> 中,我有一个有效的查询,例如:

@Query("{\"bool\": {"
        + "    \"filter\": ["
        + "        {\"term\": {\"CategoryID.keyword\": {\"value\": \"?0\"}}},"
        + "        {\"terms\": {\"Name.keyword\": [\"Name_A\",\"Name_B\",\"Name_C\"]}}"
        + "     ]"
        + "   }"
        + "}")
Stream<Product> findByCategoryIDAndNames(String categoryId, PageRequest pageRequest);

我需要 terms 值不在注释中硬编码,而是作为方法的 List<String> 参数。我找不到正确的方法来编写查询注释来查询名称集合,例如:

@Query("{\"bool\": {"
        + "    \"filter\": ["
        + "        {\"term\": {\"CategoryID.keyword\": {\"value\": \"?0\"}}},"
        + "        {\"terms\": {\"Name.keyword\": [\"?1\"]}}"
        + "     ]"
        + "   }"
        + "}")
Stream<Product> findByCategoryIDAndNames(String categoryId, List<String> names, PageRequest pageRequest);

此编译和运行没有错误,但不起作用。
查看 Spring Data Elasticsearch documentation 我找不到如何执行此操作的示例。

Spring数据弹性搜索版本:4.0.4

PR #1856 on July 3rd 2021 for the branches 4.3 to 4.1. The 4.0 branch has OSS support until May 2021 添加了对集合参数的支持,因此不再更新。