34. Model の作成
• Elasticsearch のデータ
から JSON にシリアライズ
のため必要
• Book という名のクラスを
追加
public class Book
{
public string Title { get; set; }
public string Isbn { get; set; }
public int TotalPageNumber { get; set; }
public string PictureUrl { get; set; }
public string Abstract { get; set; }
public string Description { get; set; }
public string Status { get; set; }
public string Authors { get; set; }
public string Categories { get; set; }
}
35. Elasticsearch への接続を作成
• NEST ライブラリ追加
• Startup.cs のサービス構成メソッド( )内に接続を作成
dotnet add package NEST
using Elasticsearch.Net;
using Nest;
===
var pool = new SingleNodeConnectionPool
(new Uri(“http://localhost:9200”)); //ローカル実⾏の場合
var settings = new ConnectionSettings(pool)
.DefaultIndex("books");
var client = new ElasticClient(settings);
services.AddSingleton(client);
36. Elasticsearch への接続を作成 - Elastic Cloud ⽤
•
var pool = new SingleNodeConnectionPool
(new Uri(http://localhost:9200/));
// Elastic Cloud デプロイ時に取得した値3つ (例)
https://elastic:oRHGj80iJUO6CF7WBUMiwyu1x@8009bf95
8b6w5923b3c56983d4048df824.japaneast.azure.elastic
-cloud.com:9243