私はzzz
というインデックスを持つアプリケーションを持っており、インデックスにはほとんどドキュメントをインデックスしませんでした。別のアプリケーションの1つのアプリケーションで使用される弾性検索インデックスの使用方法
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
デフォルトのインデックスをもう一度作成する必要はありません。それが存在するかどうかだけをチェックしてください。 – Brduca
あなたのアプローチでエラーが発生しました –
@PandiyanCoolエラーはありませんが、他のインデックスと検索を行っています.. – ASN