gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 13:06:36 26 4
gpt4 key购买 nike

我想使用 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 版本一起修复。

关于c# - Elasticsearch NEST DisMax MoreLikeThis 查询形成空 json 字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30598932/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com