Try our conversational search powered by Generative AI!

Nested Objects Sorting

Vote:
 

According to ES documentation: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-sort.html

That is possible to sort documents by "nested objects".

 

Does ES instance provided by episerver find supports this?

Or I doing something wrong below?

Mapping that was build in my index (extracted from it):

{
  "Commerce_Business_Search_ProductDocument": {
    "dynamic_templates": [
      {
        "nested_template": {
          "mapping": {
            "type": "nested"
          },
          "match": "*$$nested"
        }
      }
    ],

    "properties": {

      "Prices$$nested": {
        "type": "nested",
        "properties": {

          "UnitPrice$$number": {
            "type": "double",
            "ignore_malformed": false
          }
        }
      }
    }
  }
}

Query:

{
    "sort": [{
        "UnitPrice$$number": {
            "nested_path": "Prices$$nested",
            "mode": "min",
            "order": "desc",
            "ignore_unmapped": false
        }
    }],
    "fields": ["___types", "Prices$$nested"]
}

        

Hits from index (I have only 2 documents there)

[
    {
        "_index": "yauheni_myindex",
        "_type": "Commerce_Business_Search_ProductDocument",
        "_id": "247",
        "_score": null,
        "fields": {
            "Prices$$nested": [
            {
                "___types": [
                    "Commerce.Business.Search.ProductPrice",
                    "System.Object"
                ],
                "ValidFrom$$date": "2014-03-19T12:11:00Z",
                "Warehouse$$string": "",
                "UnitPrice$$number": 10,
                "$type": "Commerce.Business.Search.ProductPrice, Commerce.Business",
                "Market$$string": "Sweden",
                "ValidUntil$$date": "2015-03-19T12:11:00Z"
            }
            ],
            "___types": [
            "Commerce.Business.Search.ProductDocument",
            "System.Object"
            ],
            "sort": [
              0
            ]
        }
    },
    {
        "_index": "yauheni_myindex",
        "_type": "Commerce_Business_Search_ProductDocument",
        "_id": "248",
        "_score": null,
        "fields": {
            "CatalogEntryId$$number": 248,
            "Prices$$nested": [
            {
                "___types": [
                    "Commerce.Business.Search.ProductPrice",
                    "System.Object"
                ],
                "ValidFrom$$date": "2014-03-19T12:11:00Z",
                "Warehouse$$string": "",
                "UnitPrice$$number": 20,
                "$type": "Commerce.Business.Search.ProductPrice, Commerce.Business",
                "Market$$string": "Sweden",
                "ValidUntil$$date": "2015-03-19T12:11:00Z"
            }
            ],
            "___types": [
            "Commerce.Business.Search.ProductDocument",
            "System.Object"
            ],
            "sort": [
              0
            ]
        }
    }
]

    

Hits are not sorted, and "sort" fields equals 0 for both of them.

 

 

#82766
Mar 19, 2014 14:18
Vote:
 

Just to clarify, I've omitted some "useless" data from snippets above (i.e. all properties mappings)

#82772
Edited, Mar 19, 2014 14:26
Vote:
 

No, nested objects is not supported by the standard installation.

#82827
Mar 20, 2014 9:59
Vote:
 

By currenlty I'm able to use nested facets and filters.

#82835
Mar 20, 2014 10:38
Vote:
 

To clearify: You can use nested objects for searching/faceting (although there is no API support for that). What is not supported is sorting.

Best Regards,
Henrik

#83126
Edited, Mar 26, 2014 11:06
Vote:
 

Thank you, Henrik.

I do use faceting/filtering by nested objects (I've made simple extension for find API).

But still can't understand why standard ElasticSearc feature is disabled by epi find service, that was a greate surprise :)

And this is really a pain in my case when I have product with multiple prices (each price has time range when it is active) and want to sort products by "actual" price (that mets current time condition).

I think that is very common case for e-commerce application; for instance, EPiServer Commerce does support multiple prices, but find provider it has does calculate actual price during indexing. So reindexing of catalog (in my case 40 000+) products is required at least every day.

Only options I see do sorting/paging on client or reindex all my products every day. But I still don't want to go with this "ugly" solutions and afraid performance degradation they may lead to.

 

 

#83129
Edited, Mar 26, 2014 12:05
Vote:
 

To whomever like me gets this as the first result in Google: please note that this post was answered in 2014 and back then it was not possible to do it. In the latest versions of the Find API this is totally possible:

https://world.episerver.com/documentation/developer-guides/find/NET-Client-API/searching/nested-queries/

Hope it helps!

#202675
Mar 28, 2019 18:32
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.