[英]Bulk insert to ElasticSearch with NEST
I try to add 100k products to elasticsearch, but when i try i get: {"Validation Failed: 1: no requests added;"} 我尝试向elasticsearch添加100k产品,但是当我尝试获取时:{“验证失败:1:没有添加请求;”}
My code: 我的代码:
var Node = new Uri("......");
var ConnectionPool = new SniffingConnectionPool(new[] { Node });
var Config = new ConnectionConfiguration(ConnectionPool)
.SniffOnConnectionFault(false)
.SniffOnStartup(false)
.SniffLifeSpan(TimeSpan.FromMinutes(10));
var Client = new ElasticsearchClient(Config);
var AllProducts = Product.GetProducts();
var SPl = AllProducts.Split(100); // Split into 100 collections/requests
var COll = new List<ElasticsearchResponse<DynamicDictionary>>();
foreach (var I in SPl)
{
var Descriptor = new BulkDescriptor();
foreach (var Product in I)
{
Descriptor.Index<Product>(op => op.Document(Product));
}
COll.Add(Client.Bulk(Descriptor));
}
AllProducts contains a list of this object: AllProducts包含此对象的列表:
public class Product
{
public int AffiliateNr { get; set; }
public string AffiliateProductId { get; set; }
public int BrandNr { get; set; }
public string Currency { get; set; }
public string IndexId { get; set; }
public decimal Price { get; set; }
public long ProductNr { get; set; }
public string Title { get; set; }
}
So, 所以,
Refering to your previous problem, you can use IndexMany for indexing the data. 请参阅上一个问题,您可以使用IndexMany索引数据。 Now as per your question in comment, you can specify the id which elastic search will use.
现在根据您在评论中的问题,您可以指定弹性搜索将使用的ID。 see the below example.
见下面的例子。
ElasticType(IdProperty = "<fieldName>")]
public class ClassName
{
if you dont want to specify any Id to elastic search, create a dummy field dummyId(nullable) and put it in "IdProperty". 如果你不想指定任何Id到弹性搜索,创建一个虚拟字段dummyId(可空)并将其放在“IdProperty”中。 Elastic search will auto assign the value to it if it null.
如果弹性搜索为空,则弹性搜索将自动为其分配值。
Edit : From 2.3 onwards, Its 编辑:从2.3开始,它
[ElasticsearchType(IdProperty = "<fieldName>")]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.