I'm working on a sample project which will have MongoDB and Elasticsearch. After a long research, I've choose Mongo-Connector to make the sync between MongoDB and Elasticsearch. The sync between them is already working fine.
I've inserted a lot of documents on my MongoDB. Basically the document reference to a "Person". The document has this basic json structure:
{
"Id": "5a308536-0bd9-47e6-8bdb-438dafd0488c",
"Name": "Seal",
"ExtraElements": {
"DateofBirth": "2001-12-27T03:41:30.333Z",
"Age": 56,
"Gender": "F"
}
}
The json above maps to this .net class
public class Person
{
public string Id { get; set; }
public string Name { get; set; }
public Dictionary<string, object> ExtraElements { get; set; }
}
As you can figure the "ExtraElements" is a dictionary to store N fields. We need this because we don't know how many fields we'll have.
When I insert a json like that in my MongoDB, it gets mapped into a document with this structure:
Person
Id
Name
DateofBirth
...
...
With Mongo-Connector in place and working, when I've inserted the first document on MongoDB the same document was inserted on Elasticsearch. Since I didn't have a type, it was created on the fly, using dynamic mapping. The mapping created on Elasticsearch is this:
{
"repository" : {
"mappings" : {
"Person" : {
"properties" : {
"DateofBirth" : {
"type" : "date",
"format" : "dateOptionalTime"
},
"Age" : {
"type" : "long"
},
"Gender" : {
"type": "string"
}
"Name" : {
"type" : "string"
}
}
}
}
} }
As you can see, the ExtraElements fields were created as a "flat" document, or all the fields are in the same "level" meaning that there aren't no nested types.
My question now is: I'm using NEST to query on Elasticsearch, but when I do that, I only get the Id and Name values, the ExtraElements dictionary is null. Did I did something wrong with the mapping stuff on Elasticsearch? Is there a way in c# or NEST to map this?