Search code examples
azure-cognitive-search

The order of items in Azure Index is different from the original JSON file


I have a json file containing 300 items. I have uploaded it to Azure Search but after indexing I realized the order was not the same as the original json file.

Meaning that in my json, the first item has the title Burger Sauce. But search query returned Chocolate as the first product.

I have not set any scoring profile. I was expecting the order of items when I search all is the same as the original json file.

Is there any way to configure the search result have the exact same order as the original json file?


Solution

  • The indexing order is not preserved in Azure Search.

    If you want to sort your results using a specific value, you can use the orderby parameter: https://learn.microsoft.com/en-us/rest/api/searchservice/search-documents#orderbystring-optional

    To reproduce the indexing order when returning all documents from your index, you could add an "Indexing order" field to your index definition that you would populate with increasing numbers, and then use that field to sort your results.