How to use api get mutil parent/child inner_hits

i'm using the version 6.3.2.
use the client

org.elasticsearch
elasticsearch
6.3.2

how to use api get mutil parent/child inner_hits?

//code the api below is get dept and their users

@RequestMapping("/queryDetails")
public void queryDetails() {
	QueryBuilder qb = JoinQueryBuilders.hasChildQuery("user", // child relation
			QueryBuilders.matchQuery("uname.keyword", "lucy"), ScoreMode.None).innerHit(new InnerHitBuilder());
	SearchQuery searchQuery = new NativeSearchQueryBuilder().withIndices("user_test").withQuery(qb).build();
	
	
	List<DeptVO> depts = elasticsearchTemplate.query(searchQuery, searchResponse -> {
		SearchHits hits = searchResponse.getHits();
		List<DeptVO> list = new ArrayList<>();
		Arrays.stream(hits.getHits()).forEach(h -> {
			Map<String, Object> source = h.getSourceAsMap();
			SearchHits innerHitsMap = h.getInnerHits().get("user");// get child

			List<User> user1s = Arrays.stream(innerHitsMap.getHits()).map(innerH -> {
				Map<String, Object> innerSource = innerH.getSourceAsMap();
				return new User(innerSource.get("uname").toString(),
						Integer.valueOf(innerSource.get("age").toString()));
			}).collect(Collectors.toList());
			list.add(new DeptVO(source.get("dname").toString(), user1s));
		});
		return list;
	});
}

if i have child in "user", like address, how to get it?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.