8

我尝试将 100k 产品添加到 elasticsearch,但是当我尝试时我得到:{“验证失败:1:没有添加请求;”}

我的代码:

        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. 我在哪里可以设置索引的名称?
  2. 为什么我得到,验证失败:1:没有添加请求;?
  3. IndexId 是我的产品 ID。我如何告诉 Elasticsearch 使用这个 id?或者我必须指定一个ID?
4

1 回答 1

7

参考您之前的问题,您可以使用 IndexMany 对数据进行索引。现在根据您在评论中提出的问题,您可以指定弹性搜索将使用的 id。请参见下面的示例。

  ElasticType(IdProperty = "<fieldName>")]
    public class ClassName
    {

如果您不想为弹性搜索指定任何 Id,请创建一个虚拟字段 dummyId(nullable) 并将其放入“IdProperty”中。如果它为空,弹性搜索将自动为其分配值。

编辑:从 2.3 开始,它

[ElasticsearchType(IdProperty = "<fieldName>")]
于 2015-06-05T10:39:05.850 回答