【问题标题】:Inner Hits isn't working ElasticSearchInner Hits 不起作用 ElasticSearch
【发布时间】:2018-07-08 05:38:30
【问题描述】:

美好的一天:

我正在使用 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:
{}

如您所见,请求为空。

【问题讨论】:

    标签: elasticsearch nest


    【解决方案1】:

    您尚未使用所有需要的属性定义嵌套查询;它缺少 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"))
                        )
                    )
                )
            )
        );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-10
      • 1970-01-01
      • 2015-12-24
      相关资源
      最近更新 更多