FTS search works but sorting doesn't

Here is the FTS query I use on a bucket with 1000 documents. The query works fine, but sort returns very weird answers.

  "indexName": "idx_listUsersSearch",
  "query": {
    "conjuncts": [
      {
        "term": "users",
        "field": "docType"
      },
      {
        "term": "users",
        "field": "namespace"
      }
    ]
  },
  "sort": [
    {
      "by": "field",
      "field": "data.info.firstName",
      "missing": "last"
    }
  ],
  "size": 5,
  "from": 0
}

RESULT when limited to 5:
Adriana
Corina
FirstName
Florin
Belinda

RESULT when limited to 10:
Adriana
Corina
FirstName
Martina
Florin
Belinda
Meg

Reverse order and sorting by -data.info.firstName generates the following results
Meg
Adriana
Belinda
Zhara
Xtina
Megan

you get the point.

I still can’t believe I’m spending time on sorting?!
How is this not solved???

Having a similar problem waiting for someone to guide me fix the issue

Thanks in advance.

@Gabriel_P1 would you mind sharing your index definition? The sorting of your field values depends on the tokens generated for your text - which is done by the analyzer. So what analyzer were you using? If you want to sort correctly on the first name, I’d recommend using the keyword analyzer.

Also, just updating your field from “data.info.firstName” to “-data.info.firstName” isn’t the right way to reverse sort. You’d need to set {“desc”:true} within your sort object. So that’d look like this …

 "sort": [
    {
      "by": "field",
      "field": "data.info.firstName",
      "missing": "last",
      "desc": true
    }
  ]

Optionally you could do this …

"sort": ["data.info.firstName"] // ascending
..
"sort": ["-data.info.firstName"] // descending

Documentation on sorting … https://docs.couchbase.com/server/6.5/fts/fts-sorting.html

Still waiting for someone to help me resolve my issue? vlc 9apps