Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elasticsearch.NET version 7 - How to Create Index

In Elasticsearch.NET 6.x, it is possible create an index using IElasticClient method:

var response = elasticClient.Create(
                    "my-index-name",
                    index =>  index .Mappings(
                        ms => ms.Map<MyDocumentType>(
                            x => x.AutoMap()
                        )
                    )
                );

Method is removed in Elasticsearch.NET version 7.

like image 764
Nenad Avatar asked Jul 01 '19 13:07

Nenad


People also ask

Does Elasticsearch automatically create index?

By default, Elasticsearch has a feature that will automatically create indices. Simply pushing data into a non-existing index will cause that index to be created with mappings inferred from the data.

How is Elasticsearch indexed?

In Elasticsearch, an index (plural: indices) contains a schema and can have one or more shards and replicas. An Elasticsearch index is divided into shards and each shard is an instance of a Lucene index. Indices are used to store the documents in dedicated data structures corresponding to the data type of fields.

Does Logstash create index in Elasticsearch?

Logstash does not create index on elasticsearch.


1 Answers

In Elasticsearch.NET version 7 methods related to indices operations are moved into IndicesNamespace, so IndexExists method has been moved to:

var response = elasticClient.Indices.Create(IndexName,
                    index => index.Map<ElasticsearchDocument>(
                        x => x.AutoMap()
                    ));

Also note, that Map(...) method is no longer nested inside of Mappings(...) method. Reason is that Elasticsearch server version 7 supports does not support multiple types per index (see Removal of mapping types), so one Map method per index is sufficient.

Similarly, different methods have been moved to their own namespaces:

  • Cat
  • Cluster
  • Graph
  • Sql
  • Nodes
  • etc...
like image 196
Nenad Avatar answered Sep 19 '22 17:09

Nenad