内部点击不工作 ElasticSearch
Inner Hits isn't working ElasticSearch
美好的一天:
我正在使用 ElasticSearch/NEST 查询嵌套对象。我意识到我的嵌套对象是空的,尽管现在匹配,但父对象正在返回。
ISearchResponse<Facility> responses = await this._elasticClient.SearchAsync<Facility>(a => a.Query(q =>
q.Bool(b =>
b.Must(m =>
m.Nested(n =>
n.Query(nq =>
nq.Term(t =>t.Field(f => f.Reviews.First().UserId).Value(user.Id))
).InnerHits(ih => ih.From(0).Size(1).Name("UserWithReview"))
)
)
)
));
当我查看生成的查询时,我更加困惑发生了什么:
Successful low level call on POST: /dev/doc/_search?typed_keys=true
# Audit trail of this API call:
- [1] HealthyResponse: Node: http://localhost:9200/ Took: 00:00:00.9806442
# Request:
{}
如您所见,请求为空。
您尚未定义具有所有所需属性的嵌套查询;它缺少 Path
属性,它告诉 Elasticsearch 在哪个文档字段(即路径)上执行查询。查看查询的其余部分,看起来应该是 Reviews
属性
ISearchResponse<Facility> responses =
await this._elasticClient.SearchAsync<Facility>(a => a
.Query(q => q
.Bool(b => b
.Must(m => m
.Nested(n => n
.Path(f => f.Reviews) // <-- missing
.Query(nq => nq
.Term(t => t
.Field(f => f.Reviews.First().UserId)
.Value(user.Id)
)
)
.InnerHits(ih => ih.From(0).Size(1).Name("UserWithReview"))
)
)
)
)
);
美好的一天:
我正在使用 ElasticSearch/NEST 查询嵌套对象。我意识到我的嵌套对象是空的,尽管现在匹配,但父对象正在返回。
ISearchResponse<Facility> responses = await this._elasticClient.SearchAsync<Facility>(a => a.Query(q =>
q.Bool(b =>
b.Must(m =>
m.Nested(n =>
n.Query(nq =>
nq.Term(t =>t.Field(f => f.Reviews.First().UserId).Value(user.Id))
).InnerHits(ih => ih.From(0).Size(1).Name("UserWithReview"))
)
)
)
));
当我查看生成的查询时,我更加困惑发生了什么:
Successful low level call on POST: /dev/doc/_search?typed_keys=true
# Audit trail of this API call:
- [1] HealthyResponse: Node: http://localhost:9200/ Took: 00:00:00.9806442
# Request:
{}
如您所见,请求为空。
您尚未定义具有所有所需属性的嵌套查询;它缺少 Path
属性,它告诉 Elasticsearch 在哪个文档字段(即路径)上执行查询。查看查询的其余部分,看起来应该是 Reviews
属性
ISearchResponse<Facility> responses =
await this._elasticClient.SearchAsync<Facility>(a => a
.Query(q => q
.Bool(b => b
.Must(m => m
.Nested(n => n
.Path(f => f.Reviews) // <-- missing
.Query(nq => nq
.Term(t => t
.Field(f => f.Reviews.First().UserId)
.Value(user.Id)
)
)
.InnerHits(ih => ih.From(0).Size(1).Name("UserWithReview"))
)
)
)
)
);