Quantcast
Channel: Using Optimizely Platforms
Viewing all articles
Browse latest Browse all 8020

(400) Bad Request returned for nested query

$
0
0

Hello,

I'm trying to make working query with sorting by nested object.

I have the following extension method:

public static IEnumerable<CategorySortOrder> CategoriesSortOrder(this ProductContent product)
{
    if (product == null)
    {
        yield break;
    }
    foreach (NodeEntryRelation relation in _relationRepository.Service.GetParents<NodeEntryRelation>(product.ContentLink))
    {
        yield return new CategorySortOrder
        {
            Category = relation.Parent.ToReferenceWithoutVersion().ToString(),
            SortOrder = relation.SortOrder
        };
    }
}

which I register with custom conventions:

protected override void ApplyProductContentConventions(TypeConventionBuilder<ProductContent> conventionBuilder)
{
    base.ApplyProductContentConventions(conventionBuilder);
    conventionBuilder
        ...
        .IncludeField(x => x.CategoriesSortOrder())
        ...;
}
protected override void ApplyNestedConventions(NestedConventions nestedConventions)
{
    base.ApplyNestedConventions(nestedConventions);
    nestedConventions.ForInstancesOf<ProductContent>()
        .Add(x => x.CategoriesSortOrder());
}

As a result I can see the following data in my Find index:

{
    ...,"CategoriesSortOrder$$nested": [
        {"SortOrder$$number": 0,"___types": ["Commerce.Search.Models.CategorySortOrder","System.Object"
            ],"Category$$string": "1073741947__CatalogContent","$type": "Commerce.Search.Models.CategorySortOrder, Commerce"
        },
        {"SortOrder$$number": 0,"___types": ["Commerce.Search.Models.CategorySortOrder","System.Object"
            ],"Category$$string": "1073741971__CatalogContent","$type": "Commerce.Search.Models.CategorySortOrder, Commerce"
        }
    ],
    ...
}

or in case of no relations:

{
    ...,"CategoriesSortOrder$$nested": [],
    ...
}

And what I do during actual search is:

if (!string.IsNullOrWhiteSpace(category))
{
    search = search.OrderBy(p => p.CategoriesSortOrder(), o => o.SortOrder, o => o.Category.MatchCaseInsensitive(category), SortMissing.Last);
}

but unfortunately I receive the following exception:

EPiServer.Find.ServiceException: The remote server returned an error: (400) Bad Request.
SearchPhaseExecutionException[Failed to execute phase [query], all shards failed;
...
Parse Failure [Failed to parse source [...]
...
nested: QueryParsingException[[antonburkovsky_benefitlocal4] [nested] failed to find nested object under path [CategoriesSortOrder]];
...

All other requests without such sorting work fine without any issues.

Thanks


Viewing all articles
Browse latest Browse all 8020

Trending Articles