0
我通過jHipster使用Spring數據Elasticsearch支持,並正在努力學習更多的關於使用搜索,因爲它涉及到我的數據庫擴展一些新的關係。春數據Elasticsearch嵌套查詢
我有與它自己的指數新的嵌套關係:
@Entity
@Table(name = "friends")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@Document(indexName = "friend")
public class Friend {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@OneToOne
@Field(type=FieldType.Nested, index=FieldIndex.analyzed, store=true)
private User friend1;
@OneToOne
@Field(type=FieldType.Nested, index=FieldIndex.analyzed, store=true)
private User friend2;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public User getFriend1() {
return friend1;
}
public void setFriend1(User friend1) {
this.friend1 = friend1;
}
public User getFriend2() {
return friend2;
}
public void setFriend2(User friend2) {
this.friend2 = friend2;
}
}
我要篩選的結果給特定用戶「friend1.id」,而且比上搜索嵌套文檔匹配詳細信息?
StreamSupport
.stream(friendSearchRepository.search(
QueryBuilders.boolQuery()
.must(QueryBuilders.matchQuery("friend1.id",SecurityUtils.getCurrentUserId()))
.must(QueryBuilders.matchQuery("friend2.login",query))).spliterator(), false)
.collect(Collectors.toList());
雖然這似乎沒有返回任何結果嗎?
所以看[queryStringQuery](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html),其中包括了大量術語,但舉幾個例子,或許是:有子查詢(https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-has-child-query.html),但不要我已經以某種方式改變我的索引? –