【发布时间】:2021-04-11 18:50:39
【问题描述】:
我是使用 c# 的 Elasticsearch 和 NEST 等的新手。因此,到目前为止,我已经学会并设法编写了创建索引的代码,但问题是如何创建第二个表(类型)。如果我以同样的方式创建它,那么它只会创建一个表,而不是第二个。
代码:
public static void CreateIndex()
{
ConnectionSettings settings = new ConnectionSettings(new Uri("http://localhost:9200"));
settings.DefaultIndex("store");
ElasticClient client = new ElasticClient(settings);
client.Indices.Delete(Indices.Index("store"));
var indexSettings = client.Indices.Exists("store");
if (!indexSettings.Exists)
{
var response = client.Indices.Create(Indices.Index("store"));
}
}
public static void CreateSeed()
{
int seedValue = 1;
int limitValue = 20000;
IList<stores> List = new List<stores>();
ConnectionSettings settings = new ConnectionSettings(new Uri("http://localhost:9200"));
settings.DefaultIndex("store");
ElasticClient esClient = new ElasticClient(settings);
var item = new store() { ID = seedValue, Title = "item" + seedValue.ToString(), IsPublished = true };
var response = esClient.IndexAsync(item, idx => idx.Index("store"));
}
/// <summary>
///
/// </summary>
public static void CreateMappings()
{
ConnectionSettings settings = new ConnectionSettings(new Uri("http://localhost:9200"));
settings.DefaultIndex("store");
ElasticClient esClient = new ElasticClient(settings);
esClient.Map<stores>(m =>
{
var putMappingDescriptor = m.Index(Indices.Index("store")).AutoMap();
return putMappingDescriptor;
});
}
这会创建一个存储索引并且可以检索。但是,如果我创建另一个不同名称的表,例如itemsstore 方式相同,旧的在任何地方都不存在。
为什么?如何创建新的第二个表?
【问题讨论】:
标签: c# asp.net elasticsearch nest elasticsearch-5