1

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.

Los Morales
  • 2,061
  • 7
  • 26
  • 42

1 Answers1

1

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"
    }
Miek
  • 1,190
  • 7
  • 18
  • 1
    Thanks for the response. IIRC ES recommended to just use a different index to represent a type, i.e. a type should now be used as an index. If just using .net (not NEST), is there a way to do this from a low level standpoint and totally ignore types? – Los Morales Mar 21 '18 at 19:35
  • 1
    Yes, I think that's probably the best way to do it going forward (as ES recommends, type:index as 1:1) All of our data is transmitted in the .net dict structure interacting with (we still use NEST, just none of its type/mapping functionality). I believe elastic itself is still going to be expecting a type parameter (This may no longer be the case in 6, but that's the reason we had the placeholder string "Document" all of our documents). If your version of elastic isn't expecting a type, I don't see why you couldn't do this with the low-level lib or forming the requests yourself. – Miek Mar 21 '18 at 22:25