How to build a unit test expected query for Nest 6.x with nested values

北战南征 提交于 2019-12-24 20:55:00

问题


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.

来源:https://stackoverflow.com/questions/50839110/how-to-build-a-unit-test-expected-query-for-nest-6-x-with-nested-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!