How to store a c# List of objects into ElasticSearch with NEST 2.x

删除回忆录丶 提交于 2019-12-07 01:57:20

It should just work fine with AutoMap using the code in the documentation:

If the index does not exist:

var descriptor = new CreateIndexDescriptor("indexyouwant") .Mappings(ms => ms .Map<Box>(m => m.AutoMap()) );

and then call something like:

await client.CreateIndexAsync(descriptor).ConfigureAwait(false);

or, when not using async:

client.CreateIndex(descriptor);

If the index already exists

Then forget about creating the CreateIndexDescriptor part above and just call:

await client.MapAsync<Box>(m => m.Index("existingindexname").AutoMap()).ConfigureAwait(false);

or, when not using async:

client.Map<Box>(m => m.Index("existingindexname").AutoMap());

Once you succesfully created a mapping for a type, you can index the documents.

Is it possible that you first had just one category in a box and mapped that to the index (Before you made it a List)? Because then you have to manually edit the mapping I guess, for example in Sense.

I don't know if you already have important data in your index but you could also delete the whole index (the mapping will be deleted too) and try it again. But then you'll lose all the documents you already indexed at the whole index.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!