我在Sense中使用以下查询,我得到了一些结果:
POST myindex/mytype/_search
{
"query": {
"fuzzy_like_this_field" : {
"BookLabel" : {
"like_text" : "myBook",
"max_query_terms" : 12
}
}
}
}
但是使用以下代码使用Nest我什么也得不到:
var docs = client.Search<dynamic>(b => b
.Index("myindex")
.Type("mytype")
.Query(q => q
.Fuzzy(fz => fz
.OnField("BookLabel")
.Value("myBook")
)
)
).Documents.ToList();
我看不出它们之间的区别。我错过了什么?
答案 0 :(得分:0)
你上面的NEST查询产生以下查询DSL
{
"query": {
"fuzzy": {
"BookLabel": {
"value": "myBook"
}
}
}
}
要获得与fuzzy_like_this_field
查询( which is deprecated in Elasticsearch 1.6.0 and will be removed in 2.0 )最近的等效内容,您只能在您所在的字段上运行fuzzy_like_this
查询感兴趣
void Main()
{
var settings = new ConnectionSettings(new Uri("http://localhost:9200"));
var connection = new InMemoryConnection(settings);
var client = new ElasticClient(connection: connection);
var docs = client.Search<dynamic>(b => b
.Index("myindex")
.Type("mytype")
.Query(q => q
.FuzzyLikeThis(fz => fz
.LikeText("myBook")
.MaxQueryTerms(12)
.OnFields(new [] { "BookLabel" })
)
)
);
Console.WriteLine(Encoding.UTF8.GetString(docs.RequestInformation.Request));
}
这将输出以下查询DSL
{
"query": {
"flt": {
"fields": [
"BookLabel"
],
"like_text": "myBook",
"max_query_terms": 12
}
}
}
应该产生与您在Sense中看到的相同的结果。