Reputation: 2155
Looking to use ElasticSearch as well as Net/NEST and was wondering what would be the appropriate way to index a document and NOT use a type? Looking at the NEST docs, it looks to automatically create a type from a POCO, so am not sure how to bypass this and/or best practice to use. I'm asking this due to reading about type removal in future versions of ES (7+). Would like to start off in the right way if going the ES route.
Upvotes: 1
Views: 427
Reputation: 1228
I had to tackle this problem not too long ago when we were looking at the 5->6 roadmap.
The simplest solution I found was to just use a single "universal" type, and begin storing what would formerly be considered a "type" to their own indices. If it's possible for you to override the "type" value being output by the serializer, you could set that to a default "_type" of your own, while applying a "type" keyword field to each new document that you insert. Once types truly go away, drop this placeholder _type all together.
I don't use the NEST type conversion functionality, and push all data into a single type that is mapped at the same time as index creation ("Document", as below) as standard .net dictionaries. At the application level, I updated our request parser (we route requests to elastic through an application, rather than directly) to translate the type parameters into a filter using the "type" field.
Here's what a document on my index looks like:
{
"_index": "an_index",
"_type": "Document",
"_id": "COEa100H00000D7AOcQAN",
"_score": 1,
"_source": {
"title": "Document title"
"id": "COEa100H00000D7AOcQAN",
"type": "KeywordFieldForFilteringType"
}
Upvotes: 1