1

I am using version 5.0 of Nest with ElasticSearch. I have an object which looks like this:

[ElasticsearchType(IdProperty = "messageId")]
public class Message
{
    public Message() { }
    public string messageId { get; set; }
    public string conversationId { get; set; }       
    public dynamic context { get; set; }

}

As you can see, I am trying to have a very dynamic object - where context could contain any kind of data.

Will this work? What is the best way to work with dynamic types in ElasticSearch?

I need to be able to query the data using the data within context.

For example, context could contain any kind of property and even hierarchical data. Examples:

{
     Name: "Billy Bob",
     Age: 12,
     Zip: 33312,
     Interests: ["cars","planes","rockets"]
}

Another example:

{
     Name: "Jill Smith",
     Age: 32,
     Zip: 33312,
     Occupation: "Developer",
     Children:[
          {
             Name:"Martha",
             Age: 12
          },
          {
             Name:"John",
             Activity: "Dancing"
          },
     ]

}
Simcha Khabinsky
  • 1,970
  • 2
  • 19
  • 34
  • Yes this works - it just skips the compiler checks, so it allows it to move forward. You still have to handle it properly though. Put it through some paces with try blocks, and throw your errors when you run across a new and unexpected return type; add another condition; and repeat. The better option would be to cast the JSON directly to an object. Then all the "field names" are properties of the object. [LINK](http://stackoverflow.com/questions/2246694/how-to-convert-json-object-to-custom-c-sharp-object) – Rick Riggs Apr 20 '17 at 23:41
  • is this working, because I am trying to search dictionary and it does not return me any results using NEST, however the say query works on Kibana. – Milad Rezazadeh Aug 23 '17 at 12:07

0 Answers0