Skip to content

Instantly share code, notes, and snippets.

@spati-java
Created September 14, 2018 14:59
Show Gist options
  • Save spati-java/57acb2e269ed781a5a765fa2cf0c9093 to your computer and use it in GitHub Desktop.
Save spati-java/57acb2e269ed781a5a765fa2cf0c9093 to your computer and use it in GitHub Desktop.
public List<ProfileDocument> searchByTechnology(String technology) throws Exception {
SearchRequest searchRequest = new SearchRequest();
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
QueryBuilder queryBuilder = QueryBuilders
.boolQuery()
.must(QueryBuilders
.matchQuery("technologies.name", technology));
searchSourceBuilder.query(QueryBuilders
.nestedQuery("technologies",
queryBuilder,
ScoreMode.Avg));
searchRequest.source(searchSourceBuilder);
SearchResponse response =
client.search(searchRequest, RequestOptions.DEFAULT);
return getSearchResult(response);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment