【发布时间】:2015-06-02 14:28:02
【问题描述】:
我想通过 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。
这是我的课,如果它有帮助的话:
[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 中的文档没有解释或给出基本概念。
谢谢。
【问题讨论】:
-
看起来像一个错误。这个问题的公关在这里github.com/elastic/elasticsearch-net/pull/1431
-
@Rob 好吧,谢谢先生,希望开发人员能解决它。 :)
-
@Rob 也许您可以提交您的评论作为答案,这样我就可以投票并将其标记为已接受?
-
没关系。谢谢:)
标签: c# json elasticsearch nest morelikethis