0

This is a follow up question for another post which I had asked (and been answer) how to build a unit test to a specific query in ElasticSearch using Nest (in c#). this is a code sample from the answer which I was given in which I build an expected query for "normal" tags:

    var expected = new 
    {
    query = new {
        @bool = new {
            must = new object[] {
                new {
                    @bool = new {
                        should = new object[] {
                            new {
                                match = new {
                                    title = new {
                                        query = "Kibana"
                                    }
                                }
                            },
                            new {
                                match = new {
                                    title = new {
                                        query = "Elasticsearch",
                                        boost = 2d
                                    }
                                }
                            }
                        },
                    }
                },
                new {
                    @bool = new {
                        filter = new [] {
                            new {
                                range = new {
                                    score = new {
                                        gt = 0d
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
};

I didn't managed to turn one of those tags into a nested one. i.e. field.title

In my tested query object I created this property using JsonProperty in the following way:

[JsonProperty(PropertyName = "field.title")]
public object { get; set; }

but I didn't mange to do something similar in my unit test to 'mock' his creation. Any help will be deeply appreciated.

Green
  • 2,405
  • 3
  • 22
  • 46
  • 1
    If I understand the question correctly, you'd like to know how to create an anonymous type property with a `.` (dot) in the name? If that's the case, you can't, *but*, since this is only be used to generate JSON to compare, you can use a `Dictionary`, or `JObject`. Take a look at this NEST integration test for example, that uses the former to express the aggregation JSON structure: https://github.com/elastic/elasticsearch-net/blob/5798ab8a5706b0b6fa7ef7235de17c7a066a2ec9/src/Tests/Aggregations/Bucket/Filter/FilterAggregationUsageTests.cs#L27-L43 – Russ Cam Jun 13 '18 at 14:46
  • cool. I was guessing I had to go in another way to do so (now it works with a Json string - but my eyes didn't like whats they saw one bit). I will give it a try. – Green Jun 13 '18 at 15:31

0 Answers0