我嘗試添加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