【发布时间】:2016-08-24 11:01:33
【问题描述】:
我有一个索引为zzz 的应用程序,我在索引中索引了一些文档。
string configvalue1 = ConfigurationManager.AppSettings["http://localhost:9200/"];
var pool = new SingleNodeConnectionPool(new Uri(configvalue1));
var defaultIndex = "zzz";
**settings = new ConnectionSettings(pool)
.DefaultIndex(defaultIndex)
.MapDefaultTypeNames(m => m.Add(typeof(Class1), "type"))
.PrettyJson()
.DisableDirectStreaming();
client = new ElasticClient(settings);**
if (client.IndexExists(defaultIndex).Exists && ConfigurationManager.AppSettings["syncMode"] == "Full")
{
client.DeleteIndex(defaultIndex);
client.CreateIndex(defaultIndex);
}
return client;
现在在一个全新的应用程序中,我必须检查zzz 是否存在,并将其用于某些搜索操作。我还需要在上面的代码中编写** 之间的所有内容,还是只连接到池并检查索引?
这是我的看法:
configvalue1 = ConfigurationManager.AppSettings["http://localhost:9200/"];
var pool = new SingleNodeConnectionPool(new Uri(configvalue1));
settings = new ConnectionSettings(pool);
client = new ElasticClient(settings);
// to check if the index exists and return if exist
if (client.IndexExists("zzz").Exists)
{
return client;
}
只是添加到上面的问题:
我想在索引之前实现一些这样的条件:
Index doesnt exist && sync mode == full --> Create index
Index exist && sync mode==full --> Delete old index and create a new
Index doesnt exist && sync mode == new --> Create index
Index exist && sync mode==new --> Use the existing index
TIA
【问题讨论】:
-
您不必再次创建默认索引。只需检查它是否存在。
-
您的方法是否有任何错误
-
@PandiyanCool 没有错误.. 但它需要一些其他索引和搜索..
-
@ASN 然后尝试通过指向特定索引来运行您的搜索查询
-
@PandiyanCool 我只是按照下面的答案并指向一个特定的索引并尝试过。它仍在使用另一个索引进行搜索。您可以在 Russ Cam 提供的答案下方阅读我的评论以获取更多信息。 TIA :)
标签: c# asp.net .net elasticsearch nest