我已经使用NEST进行elasticsearch一段时间了,直到现在我已经使用了常规的ElasticSearchClient.Index(...)函数,但现在我想索引很多批量操作中的项目。NEST - IndexMany不索引我的对象
我发现了IndexMany(...)函数,但是我必须做一些错误的事情,因为它没有像常规Index(...)函数那样添加到弹性搜索数据库中?
有没有人有任何想法?
在此先感谢!
我已经使用NEST进行elasticsearch一段时间了,直到现在我已经使用了常规的ElasticSearchClient.Index(...)函数,但现在我想索引很多批量操作中的项目。NEST - IndexMany不索引我的对象
我发现了IndexMany(...)函数,但是我必须做一些错误的事情,因为它没有像常规Index(...)函数那样添加到弹性搜索数据库中?
有没有人有任何想法?
在此先感谢!
我发现这个问题。我必须在索引中指定索引名称IndexMany
var res = ElasticClient.CreateIndex("pages", i => i.Mappings(m => m.Map<ESPageViewModel>(mm => mm.AutoMap())));
var page = new ESPageViewModel
{
Id = dbPage.Id,
PageId = dbPage.PageId,
Name = dbPage.Name,
Options = pageTags,
CustomerCategoryId = saveTagOptions.CustomerCategoryId,
Link = dbPage.Link,
Price = dbPage.Price
};
var pages = new List<ESPageViewModel>() { page };
var res2 = ElasticClient.IndexManyAsync<ESPageViewModel>(pages, "pages");
这可按预期工作。猜猜我可以在配置中指定一个默认索引名称,以避免为IndexMany调用指定索引。
如果您使用的是C#,您应该创建一个要插入的对象列表,然后调用IndexMany函数。
例子:
List<Business> businessList = new List<Business>();
#region Fill the business list
...............................
#endregion
if (businessList.Count == 1000) // the size of the bulk.
{
EsClient.IndexMany<Business>(businessList, IndexName);
businessList.Clear();
}
而在最后,再次检查
if (businessList.Count > 0)
{
EsClient.IndexMany<Business>(businessList, IndexName);
}
你想同时索引多少个“东西”?大小是多少? HTTP内容长度限制实施的大小限制约为100MB。 –
对于我的测试,我只使用2个项目,并没有一个在我的索引中结束。我知道限制:)而且我也没有从IndexMany(...)函数得到任何错误:/ –
响应中的'.DebugInformation'属性是什么意思? –