是否存在关于如何将NEST 1.x中编写的代码更改为2.x?
的文档我看过这些网站并且它们不完整:
https://github.com/elastic/elasticsearch-net/blob/master/docs/2.0-breaking-changes/nest-breaking-changes.md
https://github.com/elastic/elasticsearch-net
https://www.elastic.co/blog/ga-release-of-nest-2-0-our-dot-net-client-for-elasticsearch
例如,我想知道如何替换以下内容:
1)
given ISearchResponse<T> searchResults = ...
怎么做:
searchResults.ConnectionStatus
searchResults.RequestInformation.Request
2)
client.Get<T>(s => s.Id(id));
3)
给定QueryContainer query
new SearchDescriptor<T>()
.From(from)
.Size(pageSize)
.Query(query); //this dosen't work anymore
4) MatchQuery不接受fuziness作为双字符串和类型参数作为字符串用于
5)QueryDescriptor似乎消失了 gasp
6)client.Update已被破坏
var result = client.Update<CustomerProfile>(request => request
.Id(customer.CustomerId)
.Doc(customer)
.Refresh()
);
7)client.Get以类似于client.Update
的方式被破坏8)在Mappings中,以下设置不再起作用
CreateIndexDescriptor cid = ...
cid.NumberOfReplicas(numReplicas)
.NumberOfShards(numShards)
.Settings(s => s
.Add("merge.policy.merge_factor", "10")
.Add("search.slowlog.threshold.fetch.warn", "1s")
)
.Analysis(a => a.TokenFilters etc etc
编辑
9)日期范围:
startDate和endDate是DateTime类型
var qd = new QueryContainerDescriptor<EsActivity>();
QueryContainer qc = qd.Range(r =>
r.Field("esactivity.timestamp")
.GreaterThanOrEquals(DateMath.Anchored(startDate))
.LessThanOrEquals(DateMath.Anchored(endDate))
);
.GreaterThanOrEquals
需要一个double
参数,但在文档页面上需要DateMath.Anchored(startDate)
10)突出显示:
highlightFields: List<string>
Action<HighlightFieldDescriptor<T>> [] tmp = highlightFields.Select(field =>
new Action<HighlightFieldDescriptor<T>>(
highlighter => highlighter.Field(field)
)
).ToArray();
sd:SearchDescriptor<..>..
sd.Highlight(h => h
.PreTags(preTag)
.PostTags(postTag)
.OnFields(tmp)
);
我发现我可以用OnFields(tmp)
替换.Fields(f=>f.OnAll())
,但我还是想以某种方式自己指定字段。
为什么有一个HighlightQuery选项可用,因为我们已经在查询对象上应用了突出显示..现在有2个查询调用。
我已将上面的突出显示转换为
var tmp = highlightFields.Select(field =>
Tuple.Create<Field, IHighlightField>(
Field.Create(field),
new HighlightField()
)
).ToDictionary(x => x.Item1, x => x.Item2);
sd.Highlight(h => new Highlight
{
PreTags = new[] { preTag },
PostTags = new[] { postTag },
Fields = tmp
}
);
答案 0 :(得分:1)
1)searchResults.ApiCall
取代searchResults .ConnectionStatus
。
您可以使用searchResults.ApiCall.RequestBodyInBytes
获取请求字节,并且还需要在.DisableDirectStreaming()
上设置ConnectionSettings
以便在请求直接写入请求流时捕获字节默认值。
2)使用client.Get<T>(id)
- 第一个参数是DocumentPath<T>
type。
3)要将QueryContainer
传递给Fluent API描述符,只需从Func<QueryContainerDescriptor<T>, QueryContainer>
new SearchDescriptor<T>()
.From(from)
.Size(pageSize)
.Query(_ => query);
4)match
查询模糊为double
mapped to a formula to calculate edit distance in Elasticsearch 1.x.由于这已在Elasticsearch 2.x中删除,因此它也从NEST中删除。您可以使用
client.Search<Document>(s => s
.Query(q => q
.Match(m => m
.Query("this is my query")
.Fuzziness(Fuzziness.EditDistance(3))
)
)
);
不确定您使用type
指的是什么,但我认为您指的是文档类型?如果是这种情况,则文档类型采用Types
类型string
隐式转换为
client.Search<Document>(s => s
.Type("other-type")
.MatchAll()
);
5)QueryDescriptor<T>
已重命名为QueryContainerDescriptor<T>
,以更好地反映其构建QueryContainer
6)更新API工作
// specifying id
client.Update<Document>("document-id", u => u
.Doc(document)
.Refresh()
);
由于第一个参数是DocumentPath<T>
,因此文档实例(如果有的话)可以作为第一个参数传递
client.Update<Document>(document, u => u
.Doc(document)
.Refresh()
);
其中index,type和id将从文档实例
中推断出来7)见上文
8)修改了索引设置以反映设置在REST API json调用中出现的级别
client.CreateIndex("index-name", c => c
.Settings(s => s
.NumberOfShards(2)
.NumberOfReplicas(2)
.SlowLog(sl => sl
.Search(sls => sls
.Fetch(slsf => slsf
.ThresholdWarn("1s")
)
)
)
.Analysis(a => a) // etc...
)
);
如果您愿意,也可以使用字符串进行设置,尽管流畅的API将确保发送正确的设置值,例如: "search.slowlog.threshold.fetch.warn"
现在是"index.search.slowlog.threshold.fetch.warn"
client.CreateIndex("index-name", c => c
.Settings(s => s
.NumberOfShards(2)
.NumberOfReplicas(2)
.Setting("index.search.slowlog.threshold.fetch.warn", "1s")
.Analysis(a => a) // etc...
)
);