Elasticsearch NEST DisMax MoreLikeThis查询形成空json字符串
本文关键字:json 字符串 查询 NEST DisMax MoreLikeThis Elasticsearch | 更新日期: 2023-09-27 17:52:48
我想在使用NEST库的Elasticsearch上使用moreLikeThis查询,并为每次匹配提供不同的boost值。
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。
这是我的类,如果它有帮助的话:
[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的文档没有解释或给出如何完成的基本概念。
谢谢。
正如评论中所述,这是一个bug,将与1.5.2 NEST版本一起修复。