简体   繁体   English

elasticsearch 中的自定义查询与 spring 引导

[英]Custom query in elasticsearch with spring boot

I am new at elasticsearch and I'm trying to make a custom query with ElasticSearchRepository.我是 elasticsearch 的新手,我正在尝试使用 ElasticSearchRepository 进行自定义查询。 Input Data:输入数据:

List<Long> bookId;
Long authorId;
Timestamp from;
Timestamp to;

How could i find a number of books with List bookId , check that all of them has the same authorId and check that they were published between timestamp from ... to ... ?我怎么能找到许多带有List bookId的书,检查它们是否都具有相同的authorId并检查它们是否在...... 的时间戳之间发布?

For example i think that it could look like例如,我认为它可能看起来像

List<Books> findAllBooks (List<Long> booksId, Long authorId, Timestomp from, TimeStamp to); 

I use spring-boot-starter-data-elasticsearch我使用 spring-boot-starter-data-elasticsearch

you must create your query and add the @query annotation.您必须创建查询并添加 @query 注释。 Something like this:像这样的东西:

@Query("{"query":{"bool":{"filter":[{"range":{"field_date":{"gte":"from","lte":"to"}}}],"must":[{"term":{"authorId":{"value":"authorId"}}},{"terms":{"bookId":"booksId"}}]}}}")
List<Books> findAllBooks (@Param("booksId") List<Long> booksId, @Param("authorId") Long authorId, @Param("from") Timestomp from, @Param("to") TimeStamp to)

BoolQueryBuilder and NativeSearchQuery Api helps me a lot. BoolQueryBuilder 和 NativeSearchQuery Api 对我有很大帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM