我尝试添加100K产品elasticsearch ElasticSearch,但是当我尝试,我得到:{ “验证失败:1:没有要求加入;”}批量插入与NEST
我的代码:
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包含此对象的列表:
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; }
}
所以,
- 我在哪里可以设置索引的名称?
- 为什么我得到验证失败:1:没有添加任何请求;?
- IndexId是我产品的ID。我如何告诉Elasticsearch使用这个ID?或者我必须指定一个ID?
为什么不使用IndexMany? –
thanx。我现在有: SPl.Select(I => Client.IndexMany(I,“products”)) 它的工作原理。但是: IndexId是我的产品ID。我如何告诉Elasticsearch使用这个ID?或者我必须指定一个ID? – mrcode
将IndexId字段重命名为Id,并且elasticsearch将按惯例将此用作文档的ID。 – Manolis