elasticsearch - 内部点击无法正常工作ElasticSearch

标签 elasticsearch nest

美好的一天:

我正在使用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 - 内部点击无法正常工作ElasticSearch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51212729/

相关文章:

c# - 通过Nest中的SearchRequest类设置索引名称

c# - ElasticSearch NEST 7.x 将项目附加到现有文档对象数组属性

php - 如何访问嵌套数组值

search - 多字段,多词,不带query_string的匹配

java - 无法完全模拟 RestHighLevelClient

ElasticSearch 作为 EventStore

elasticsearch - 为什么当线程池和队列已满时,elasticsearch 会拒绝几乎所有查询,而不是尽可能多地回答并拒绝剩余的查询?

c# - 如何使用 C# NEST 客户端将 post_filter 添加到 ElasticSearch 查询?

c# - 在 IIS 下运行时无法连接到 Elasticsearch(访问 key 和 secret 不被尊重)

sorting - 使用Hibernate Search时“filtered query does not support sort”