Elasticsearch NEST DisMax MoreLikeThis 查询形成空 json 字符串

Elasticsearch NEST DisMax MoreLikeThis query forms empty json string

我想使用 NEST 库在 Elasticsearch 上使用 moreLikeThis 查询,并为每个匹配项提供不同的提升值。

var moreLikeThis = _elastic.Search<Report>(s => s
    .From(0)
    .Size(10)
    .Query(q => q
        .Filtered(f => f
            .Query(fq => fq
                .Dismax(dmx => dmx
                    .TieBreaker(0.7)
                    .Queries(qr => qr
                        .MoreLikeThis(mlt => mlt
                            .OnFields(of => of.Title.Suffix("stemmed"))
                            .MinTermFrequency(1)
                            .MaxQueryTerms(12)
                            .Boost(20)
                            .Documents(docs => docs
                                .Document()          // This is the part where I'm stuck
                            )
                        ), qr => qr
                        .MoreLikeThis(mlt => mlt
                            .OnFields(of => of.Title.Suffix("synonym"))
                            .MinTermFrequency(1)
                            .MaxQueryTerms(12)
                            .Boost(10)
                        )
                    )
                )
            )
        )
    )
);

这是我遇到的问题。我可以很容易地以原始 JSON 格式编写它,但这不是我的目标。我对 C# 和 NEST 都很陌生,不知道如何在那里传递 documentId。

这就是我的 class,如果它有帮助的话:

[ElasticType(IdProperty = "_id", Name = "reports")]
public class Report
{
    [ElasticProperty(Name = "_id", Type = FieldType.String)]
    public string _id { get; set; }

    [ElasticProperty(Name = "Title", Type = FieldType.String)]
    public string Title { get; set; }
}

这就是我用作 JSON 的查询,它工作得很好。

{
  "from": 0,
  "size": 10,
  "fields": ["Title"],
  "query": {
    "filtered": {
      "query": {
        "dis_max": {
          "tie_breaker": 0.7,
          "queries": [
            {
              "more_like_this": {
                "fields": ["Title.stemmed"],
                "docs": [
                  {
                    "_index": "test",
                    "_type": "reports",
                    "_id": "68753"
                  }
                ],
                "min_term_freq": 1,
                "max_query_terms": 12
              }
            }, {
              "more_like_this": {
                "fields": ["Title.synonym"],
                "docs": [
                  {
                    "_index": "test",
                    "_type": "reports",
                    "_id": "68753"
                  }
                ],
                "min_term_freq": 1,
                "max_query_terms": 12
              }
            }
          ]
        }
      }
    }
  }
}

NEST 中的文档没有解释或给出基本的概念是如何完成的。

谢谢。

如评论中所述,这是一个错误,将与 1.5.2 NEST 版本一起修复。