本文整理汇总了C#中Nest.ElasticClient.CreateIndex方法的典型用法代码示例。如果您正苦于以下问题:C# ElasticClient.CreateIndex方法的具体用法?C# ElasticClient.CreateIndex怎么用?C# ElasticClient.CreateIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nest.ElasticClient
的用法示例。
在下文中一共展示了ElasticClient.CreateIndex方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GameDataManager
public GameDataManager()
{
try
{
var elasticSearchUrl = ConfigurationManager.AppSettings["ElasticStoreConnection"];
var index = ConfigurationManager.AppSettings["EIndex_Game"];
_settings =
new ConnectionSettings(new Uri(elasticSearchUrl)).SetDefaultIndex(index).PluralizeTypeNames();
_client = new ElasticClient(_settings);
var isIndexExist = _client.IndexExists(i => i.Index(index));
if (!isIndexExist.Exists)
{
_client.CreateIndex(c => c.Index(index));
_settings.SetDefaultIndex(index);
_client = new ElasticClient(_settings);
}
var response =
_client.Map<Game>(
h =>
h.Properties(p => p
.String(s => s.Name(i => i.GameId).Index(FieldIndexOption.NotAnalyzed))
.String(s => s.Name(i => i.Status).Index(FieldIndexOption.NotAnalyzed))
.String(s => s.Name(i => i.TurnOfPlayer).Index(FieldIndexOption.NotAnalyzed))
.Object<Winner>(o => o.Name(w => w.Winner).Properties(wp => wp.String(f => f.Name(l => l.FacebookId).Index(FieldIndexOption.NotAnalyzed)))
)));
IsServerError(response);
}
catch (Exception ex)
{
Logger.LogException(ex, _source, "GameDataManager", Severity.Critical);
throw;
}
}
示例2: RebuildIndex
public void RebuildIndex(string userId, int? noteId)
{
if (!string.IsNullOrWhiteSpace(userId))
{
var notes = new List<NoteModel>();
if (noteId.HasValue)
notes.Add(Repository.GetById(noteId.Value));
else
notes = Repository.GetByUserId(userId).ToList();
var settings = new ConnectionSettings(new Uri("http://localhost:9200"), "mapnotes");
var client = new ElasticClient(settings);
var indexExists = client.IndexExists("mapnotes");
if (!indexExists.Exists)
{
client.CreateIndex(descriptor => descriptor.Index("mapnotes")
.AddMapping<NoteIndex>(m => m.Properties(p => p.GeoPoint(d => d.Name(f => f.Location).IndexLatLon()))));
}
foreach (var note in notes)
{
client.Index(new NoteIndex
{
Id = note.Id,
UserId = note.UserId,
Title = note.Title,
Location = new Location(note.Latitude, note.Longitude)
});
}
}
}
示例3: BlackListDataManager
public BlackListDataManager()
{
try
{
var elasticSearchUrl = ConfigurationManager.AppSettings["ElasticStoreConnection"];
var index = ConfigurationManager.AppSettings["EIndex_BlackList"];
_settings =
new ConnectionSettings(new Uri(elasticSearchUrl)).SetDefaultIndex(index).PluralizeTypeNames();
_client = new ElasticClient(_settings);
var isIndexExist = _client.IndexExists(i => i.Index(index));
if (!isIndexExist.Exists)
{
_client.CreateIndex(c => c.Index(index));
_settings.SetDefaultIndex(index);
_client = new ElasticClient(_settings);
}
var response =
_client.Map<BlockedUser>(
h =>
h.MapFromAttributes(10).Properties(p => p
.String(s => s.Name(i => i.ByEmail).Index(FieldIndexOption.NotAnalyzed))
.String(s => s.Name(i => i.ToEmail).Index(FieldIndexOption.NotAnalyzed))
));
IsServerError(response);
}
catch (Exception ex)
{
Logger.LogException(ex, _soruce, "BlackListDataManager", Severity.Critical);
throw;
}
}
示例4: GenerateAndIndex
protected static void GenerateAndIndex(ElasticClient client, string indexName, int numMessages, int bufferSize)
{
var msgGenerator = new MessageGenerator();
var tasks = new List<Task>();
var partitionedMessages = msgGenerator.Generate(numMessages).Partition(bufferSize);
client.CreateIndex(indexName, c => c
.NumberOfReplicas(0)
.NumberOfShards(1)
.Settings(s => s.Add("refresh_interval", "-1"))
.AddMapping<Message>(p=>p.MapFromAttributes())
);
Interlocked.Exchange(ref NumSent, 0);
foreach (var messages in partitionedMessages)
{
var t = client.IndexManyAsync(messages, indexName)
.ContinueWith(tt =>
{
Interlocked.Add(ref NumSent, bufferSize);
Console.WriteLine("Sent {0:0,0} messages to {1}, {2}", NumSent, indexName, tt.Result.Took);
})
;
tasks.Add(t);
}
Task.WaitAll(tasks.ToArray());
client.UpdateSettings(u => u
.Index(indexName)
.RefreshInterval("1s")
);
}
示例5: Execute
public IResponse Execute()
{
// create client connection
var node = new Uri(ServerUrl);
var conn = new ConnectionSettings(node, this.IndexName);
var client = new ElasticClient(conn);
// check index name existance
var existenceResult = client.GetIndex(i => i.Index(IndexName));
if (existenceResult.ConnectionStatus.Success)
{
// delete exist index
var deleteResult = client.DeleteIndex(i => i.Index(IndexName));
if (!deleteResult.Acknowledged)
return deleteResult;
}
// create index
var createResult = client.CreateIndex(i => i.Index(IndexName));
if (!createResult.Acknowledged)
return createResult;
// set analyzer
SetAnalyzers(client);
// put mapping
var putResult = client.Map<TranslationMemory>(m => m.Index(this.IndexName).MapFromAttributes());
//var putResult = client.Map<ElasticSearchProject>(m => m.Index(this.IndexName));
return putResult;
}
示例6: Setup
public static void Setup()
{
var client = new ElasticClient(ElasticsearchConfiguration.Settings(hostOverride: new Uri("http://localhost:9200")));
//uncomment the next line if you want to see the setup in fiddler too
//var client = ElasticsearchConfiguration.Client;
var projects = NestTestData.Data;
var people = NestTestData.People;
var boolTerms = NestTestData.BoolTerms;
var createIndexResult = client.CreateIndex(ElasticsearchConfiguration.DefaultIndex, c => c
.NumberOfReplicas(0)
.NumberOfShards(1)
.AddMapping<ElasticsearchProject>(m => m
.MapFromAttributes()
.Properties(p => p
.String(s => s.Name(ep => ep.Content).TermVector(TermVectorOption.with_positions_offsets_payloads))))
.AddMapping<Person>(m => m.MapFromAttributes())
.AddMapping<BoolTerm>(m => m.Properties(pp=>pp
.String(sm => sm.Name(p => p.Name1).Index(FieldIndexOption.not_analyzed))
.String(sm => sm.Name(p => p.Name2).Index(FieldIndexOption.not_analyzed))
))
);
var createAntotherIndexResult = client.CreateIndex(ElasticsearchConfiguration.DefaultIndex + "_clone", c => c
.NumberOfReplicas(0)
.NumberOfShards(1)
.AddMapping<ElasticsearchProject>(m => m
.MapFromAttributes()
.Properties(p => p
.String(s => s.Name(ep => ep.Content).TermVector(TermVectorOption.with_positions_offsets_payloads))))
.AddMapping<Person>(m => m.MapFromAttributes())
.AddMapping<BoolTerm>(m => m.Properties(pp => pp
.String(sm => sm.Name(p => p.Name1).Index(FieldIndexOption.not_analyzed))
.String(sm => sm.Name(p => p.Name2).Index(FieldIndexOption.not_analyzed))
))
);
var bulkResponse = client.Bulk(b=>b
.IndexMany(projects)
.IndexMany(people)
.IndexMany(boolTerms)
.Refresh()
);
}
示例7: Main
static void Main(string[] args)
{
elasticSettings = new ConnectionSettings(new Uri("http://127.0.0.1:9200"))
.SetDefaultIndex("people");
client = new ElasticClient(elasticSettings);
client.DeleteIndex("people");
// Create an index
client.CreateIndex("people", c => c
.NumberOfReplicas(0)
.NumberOfShards(1));
client.MapFluent<Person>(m => m.IndexAnalyzer("standard")
.Properties(props => props
.String(s => s
.Name(p => p.Message)
.Index(FieldIndexOption.analyzed))
.Number(n => n
.Name(p => p.Age))
.String(s => s
.Name(p => p.FirstName))
.String(s => s
.Name(p => p.Sex))
.String(s => s
.Name(p => p.LastName))));
//Add some people
var jp = new Person { FirstName = "JP", LastName = "Smith", Age = 37, Message = "OMG yay ES!", Sex = "Male" };
var matt = new Person { FirstName = "Matt", LastName = "Toto", Age = 32, Message = "I'm JPs brother", Sex = "Male" };
var christine = new Person { FirstName = "Christine", LastName = "Toto", Age = 0, Message = "I'm JPs wife", Sex = "Female" };
var kevin = new Person { FirstName = "Kevin", LastName = "Toto", Age = 26, Message = "I'm JPs other brother", Sex = "Male" };
client.Index(jp);
client.Index(matt);
client.Index(christine);
client.Index(kevin);
client.Refresh();
///// ** Wildcard search
var searchResults = client.Search<Person>(s => s
.From(0)
.Size(10)
.Query(q => q
.Wildcard(f => f.LastName, "to*", Boost: 1.0)
)
);
foreach (var result in searchResults.Documents)
{
Console.WriteLine("Found: {0}", result.FirstName + " " + result.LastName);
}
Console.ReadKey();
}
示例8: CreateIndex
/// <summary>
/// 创建索引
/// </summary>
public void CreateIndex()
{
string espath = ConfigurationManager.AppSettings["ESPath"].ToString();
string indexname = ConfigurationManager.AppSettings["IndexName"].ToString();
string typename = ConfigurationManager.AppSettings["TypeName"].ToString();
var node = new Uri(espath);
var settings = new ConnectionSettings(node);
var client = new ElasticClient(settings);
var newbase = new NewsBase();
client.CreateIndex(indexname);
client.Map<NewsBase>(m => m.MapFromAttributes());
}
示例9: ElasticsearchClient
public ElasticsearchClient()
{
this.connexion = new Uri("http://10.188.197.209:9200");
//this.connexion = new Uri("http://localhost:9200");
// this.connexion = new Uri("http://192.168.1.14:9200");
this.connexion = new Uri("http://localhost:9200");
this.settings = new ConnectionSettings(connexion, defaultIndex: "tp");
this.client = new ElasticClient(settings);
client.CreateIndex("tp");
var mapResult = client.Map<Stockobject>(c => c.MapFromAttributes().IgnoreConflicts().Type("stocks").Indices("tp"));
}
示例10: ElasticSearchConnection
//static constructor to ensure config settings are set
static ElasticSearchConnection()
{
DropShareServerName = DataMartAppSettings.Default.dropshareServerName;
DropShare = DataMartAppSettings.Default.dropshareFolderName;
ElasticSearchUrl = DataMartAppSettings.Default.elasticSearchURL;
ConnectionSettings conSettings = new ConnectionSettings(new Uri(ElasticSearchUrl));
ESClient = new ElasticClient(conSettings);
//Create the logging index in the Server if it doesn't already exists
if (!ESClient.IndexExists("logs").Exists)
{
ESClient.CreateIndex("logs");
}
}
示例11: Create
public static ElasticClient Create()
{
var esHost = ConfigurationManager.AppSettings["esHost"];
Log.DebugFormat("esHost = {0}", esHost);
var esIndex = ConfigurationManager.AppSettings["esIndex"];
Log.DebugFormat("esIndex = {0}", esIndex);
var client = new ElasticClient(new ConnectionSettings(new Uri(esHost)).SetDefaultIndex(esIndex));
//TODO: double-check
lock (Locker)
{
if (!client.IndexExists(esIndex).Exists)
client.CreateIndex(esIndex, new IndexSettings());
}
return client;
}
示例12: TestPage_Type_Mapping_Should_Create_Index_And_Return_IsValid
public static void TestPage_Type_Mapping_Should_Create_Index_And_Return_IsValid()
{
var elasticClient = new ElasticClient(new Uri("http://localhost:9200"));
var helper = new TypeScanIndexableTypeMapperResolver();
var indexableTypeMappers = helper.GetAll().ToList();
var typeMapper = indexableTypeMappers.First();
var typeMapping = typeMapper.CreateTypeMapping(new CultureInfo("en"));
var typeName = typeMapper.TypeName;
var mappingsDescriptor = new MappingsDescriptor();
mappingsDescriptor.Map<IIndexablePageData>(typeName, x => typeMapping);
var createIndexResponse = elasticClient.CreateIndex("site_en_1", x => x.Mappings(m => mappingsDescriptor));
Assert.Equal(true, createIndexResponse.IsValid);
Assert.Equal(true, createIndexResponse.Acknowledged);
}
示例13: ConfigureElasticClient
public void ConfigureElasticClient()
{
//var setting = new ConnectionSettings(new Uri("http://localhost:9200/"),Constants.INDEX_PERSON);
//setting.EnableTrace();
//setting.ExposeRawResponse();
//client = new ElasticClient(setting);
var node = new Uri(Constants.ELASTIC_SEARCH_URI);
var settings = new ConnectionSettings(node);
settings.SetDefaultIndex(Constants.INDEX_PERSON);
settings.MapDefaultTypeNames(m => m.Add(typeof(Person), (Constants.INDEX_PERSON)));
client = new ElasticClient(settings);
client.CreateIndex(ci => ci
.Index(Constants.INDEX_PERSON)
.AddMapping<Person>(m => m.MapFromAttributes()));
}
示例14: CreatePersonWithImageAttachment
public void CreatePersonWithImageAttachment()
{
var node = new Uri("http://localhost:9200");
var settings = new ConnectionSettings(
node,
defaultIndex: "my-application"
);
var client = new ElasticClient(settings);
//client.DeleteIndex("index-name");
client.CreateIndex("index-name", c => c
.AddMapping<Document>(m => m.MapFromAttributes())
);
string path = "c:\\test.png";
var attachment = new Attachment
{
Content = Convert.ToBase64String(File.ReadAllBytes(path)),
ContentType = "image/jpeg",
Name = "IMG_9896.JPG"
};
var person = new Person
{
Id = Convert.ToString(new Random(DateTime.Now.Second).Next(20000)),
Firstname = "Martijn",
Lastname = "Laarman",
File = new[] { attachment }
};
var index = client.Index(person);
var results = client.Search<Person>(s => s
.From(0)
.Size(10)
.Query(q => q
.Term(p => p.Firstname, "martijn")
)
);
}
示例15: CreateIndex
private static void CreateIndex(string name, ElasticClient client)
{
if (client.IndexExists(x => x.Index(name)).Exists)
{
Log.Logger.Information("Delete index {indexName}", name);
client.DeleteIndex(x => x.Index(name));
}
Log.Logger.Information("Create index {indexName}", name);
client.CreateIndex(name, c => c
.NumberOfReplicas(0)
.NumberOfShards(1)
.AddMapping<Book>(m => m.MapFromAttributes())
.AddMapping<CD>(m => m.MapFromAttributes()));
Log.Logger.Information("Index {indexName} created", name);
Log.Logger.Information("Closing index {indexName}", name);
Thread.Sleep(30000);
var closeRes = client.CloseIndex(x => x.Index(name));
if (!closeRes.Acknowledged)
Log.Logger.Error("Could not close index: {message}",closeRes.ServerError.Error);
Log.Logger.Information("Add analyzer to index {indexName}", name);
var res = client.Raw.IndicesPutSettings(name, File.ReadAllText("Analyzer.json"));
if (!res.Success)
Log.Logger.Error("Could not create analyzer: {error}", res.OriginalException.ToString());
Log.Logger.Information("Open index {indexName}", name);
client.OpenIndex(x => x.Index(name));
RandomBooks(1000, name, client);
RandomCDs(1000, name, client);
}