我想为此json查询创建NEST等效项:
{
"query": {
"more_like_this" : {
"fields" : ["storages.items"],
"like" : ["a","b"],
"min_term_freq": 1,
"min_doc_freq": 1
}
}
}
我的模型是:
public class Data
{
public string Name { get; set; }
public InnerStorage[] Storages { get; set; }
}
public class InnerStorage
{
public string[] Items { get; set; }
}
问题是我找不到将字符串数组传递给MoreLikeThis参数的方法。
LikeDescriptor仅包含
Text(string likeText)
和
Document(Func<LikeDocumentDescriptor<T>, ILikeDocument> selector)
我只能创建的请求是这样的
var data =
client.Search<Data>(
x =>
x.Query(
q =>
q.MoreLikeThis(
s =>
s.Fields(Field.Create("storages.items"))
.Like(sel => sel.Document(d => d.Document(
new Data(){Storages =new[]{new InnerStorage(){Items = new[] {"a", "b"}}}}
))))));
它包含完整的数据文档(但我只想传递字符串数组(项)),并为以下内容创建错误的请求:
"like": [{
"_index": null,
"_type": "data",
"doc": {
"storages": [{
"items": ["a", "b"]
}]
}
}]
最佳答案
您可以通过为每个术语调用fluent方法Text
将更多的术语添加到查询的类似部分中,如以下示例所示:
var searchResponse = client.Search<Document>(s => s
.Query(q => q
.MoreLikeThis(mlt => mlt
.Fields(f => f.Field(ff => ff.Title))
.Like(l => l.Text("a").Text("b")))));
希望能帮助到你。
关于c# - 如何在NEST中为内部数组创建MoreLikeThis查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38556092/