简体   繁体   English

使用NEST 5.x创建Elasticsearch索引

[英]Creating Elasticsearch Index using NEST 5.x

I am trying to create an index using NEST 5.x pre release version for Elasticsearch 5.x. 我正在尝试使用NEST 5.x预发布版本为Elasticsearch 5.x创建索引。 I have samples from 2.x which shows how index can be created using ElasticClient.CreateIndex method. 我有来自2.x的示例,它显示了如何使用ElasticClient.CreateIndex方法创建索引。 Below is my sample code. 以下是我的示例代码。

ESnode = new Uri("http://localhost:9200");
Nodesettings = new ConnectionSettings(ESnode);
Client = new ElasticClient(Nodesettings);

However, when I am typing below, there is NO autocomplete available. 但是,当我在下面输入时,没有可用的自动填充功能。

Client.CreateIndex( c => c.

I am able to successfully get the health of the node using below code. 我能够使用下面的代码成功获得节点的健康状况。

var res = Client.ClusterHealth();
Console.WriteLine("Status:" + res.Status);

I am having a complex document mapping for which I have defined the class structure and intend to use Automap method. 我有一个复杂的文档映射,我已经定义了类结构并打算使用Automap方法。 Hence I am trying to create the index programatically to avoid manually creating the index. 因此,我试图以编程方式创建索引,以避免手动创建索引。

I tried using some very old version of NEST (1.x) and I am able to get the autocomplete for createIndex. 我尝试使用一些非常旧版本的NEST(1.x),我能够获得createIndex的自动完成功能。 But both v2.4x and 5.x did not provide the autocomplete. 但是v2.4x和5.x都没有提供自动完成功能。 Is there a new way to create index? 有没有新的方法来创建索引? Please let me know. 请告诉我。

Thanks 谢谢

You need to supply a name to the index, in addition to the delegate that provides additional index creation options 除了提供其他索引创建选项的委托之外,您还需要为索引提供名称

var createIndexResponse = client.CreateIndex("index-name", c => c
    .Settings(s => s
        .NumberOfShards(1)
        .NumberOfReplicas(0)
    )
    .Mappings(m => m
        .Map<Conference>(d => d
            .AutoMap()
        )
    )
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM