Search code examples
node.jssdkkuzzle

Kuzzle: How to use "_kuzzle_info" to sort documents


I need to get the latest 100 documents from a specific collection so i used the search function and created from _kuzzle_info to sort documents by their date of creation but i think i have an issue with nested items as created is inside _kuzzle_info. Here is my code:

var lastHundred = await kuzzle.document.search("myIndex", "myCollection", 
    {
      query: {

      },
      sort: {
        "_kuzzle_info.created": {
          mode: "max",
          order: "asc",
          nested_path: "_kuzzle_info"
        }
      }
    })

I searched all over internet but nothing worked.So how to use the _kuzzle_info in the sort options


Solution

  • Kuzzle metadata are stored in the _kuzzle_info property of every documents:

    {
      createdAt: '<timestamp>',
      author: '<kuid>',
      updatedAt: '<timestamp>',
      updater: '<kuid>'
    }
    

    In your code snippet you are trying to sort with the _kuzzle_info.created property but you should use _kuzzle_info.createdAt.