Skip to content

Sorting using a nested dictionary field #324

Closed
@RobloxSai-zz

Description

@RobloxSai-zz

I am indexing a nested dictionary using NEST. This is the Document Class that I send up to ES:

public class Document
{
    public class Foo
    {
        public Dictionary<int, Bar> BarDict { get; set; }
    }
    public class Bar
    {
        public long Data1 { get; set; }
        public long Data2 { get; set; }
    }
    public Dictionary<int, Foo> FooDict { get; set; }
}

The data gets indexed as expected.

"fooDict" : {
    "1": {
        "barDict": {
            "1": {
                "data1": 10,
                "data2": 4
            },
            "2": {
                "data1": 16,
                "data2": 8
            }
        }
    },
    "2": {
        "barDict": {
            "4": {
                "data1": 11,
                "data2": 3
            },
            "5": {
                "data1": 2,
                "data2": 17
            }
        }
    }
}

I can sort using the following query and it returns the required output on ElasticSearch server.

"sort": {
    "fooDict.2.barDict.5.data2": {
      "order": "desc"
    }
}

However, when I use the NEST Client to generate a similar query, the "Keys" are ignored. Eg:
C# Code:
SearchDescriptor searcher;
searcher.SortDescending(s => s.FooDict[2].BarDict[5].Data2)

generates the following query:
"fooDict.barDict.data2"
which is missing the values of the Keys ("fooDict.2.barDict.5.data2").

Is there a different way to implement the Sort Function in this particular context?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions