簡體   English   中英

如何得到一個Spring數據elasticsearch查詢的結果

[英]How to get the results of a Spring data elasticsearch query

我進行了 elasticsearch 查詢以按縣查找會員頁面。

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.annotations.Query;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;

public interface MemberSearchRepository extends ElasticsearchRepository<Member, Long> {

    @Query("{\"match\": {\"county\": \"?0\"}}")
    Page<Member> findByCounty(String county);

}

總體目標是獲取查詢返回的所有 memberId,並將它們用作另一個查詢的搜索條件。 (實體“成員”有一個名為“memberId”的字段)

我嘗試使用 .getContent 獲取頁面內容(以便從頁面獲取 memberId 字段)。

Page<Member> countyResults = memberSearchRepository.findByCounty(query);

System.out.println("county results: " + countyResults.getContent().stream().collect(Collectors.groupingBy(Member::getMemberId)));

但我不知道我到底在做什么 using.collect 它返回的不僅僅是 memberId

這是它在 sysout 中顯示的內容。

Member{id=1173, memberId='123e4567-e89b-12d3-a456-426614174000', ... }

我只需要自己獲取memberId。

這對我有用

for(int i=0; i<countyResults.getContent().toArray().length; i++) {
   System.out.println("key: " + countyResults.getContent().get(i).getMemberId());
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM