Elastic order by tag value

Hi,

I have created a search index for ReturnAuthorizations in Litium 8. It uses Tags like ProductDocument for filtering in frontend for return administrators, like this:

    [Nested]
    public List<TagItem> Tags { get; set; } = new List<TagItem>();

    public class TagItem
    {
        [Keyword]
        public string Key { get; set; }

        [Keyword(EagerGlobalOrdinals = true)]
        public string Value { get; set; }
    }

I wish to sort the search based on a value in the tags list, can I do this?

I can always not use the Tags-structure, and duplicate the sortable fields onto the Document itself, then I know how to sort, but duplicated data is not nice. I use the tag structure because then I can reuse the accelerator code for filtering on tags.

Lets say I want to sort on a tag called “CountryCode”

public IPromise<IList> BuildSorting(Nest.SortDescriptor sortDescriptor, SearchQuery searchQuery)
{
var s = sortDescriptor;

… and then?

thanks,
Martin

The sort is built with something like this

return new FieldSort
{
    Field = Infer.Field<ReturnAuthorizationsDocument>(ff => ff.Tags[0].Value),
    Order = SortOrder.Ascending,
    Nested = new NestedSort
    {
        Path = Infer.Field<ReturnAuthorizationsDocument>(ff => ff.Tags),
        Filter = new TermQuery
        {
            Field = Infer.Field<ReturnAuthorizationsDocument>(ff => ff.Tags[0].Key),
            Value = item.Id
        }
    }
};

Thanks, will try next week!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.