No mapping found for [lname.raw] in order to sort on

Versions (relevant - OpenSearch/Dashboard/Server OS/Browser):

“opensearch-project/opensearch-php”: “^2.2”

Describe the issue:

We are converting from Elastic to OpenSearch in Azure, and am getting the following error
(hoping someone might be able to shed some light on why it’s saying that the mapping is not found, when it is defined–see config below–and appears to be defined the way suggested by the documentation):
{
“type”:“query_shard_exception”,
“reason”:“No mapping found for [lname.raw] in order to sort on”,

}

On the query:

{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "familyRelationship": "Primary"
          }
        }
      ]
    }
  },
  "sort": {
    "lname.raw": "asc"
  }
}

Configuration:

{
  "mappings": {
    "properties": {
      "familyRelationship": {
        "type": "keyword"
      },
      "lname": {
        "type": "text",
        "fields": {
          "raw": {
            "type": "keyword"
          }
        }
      }
    }
  }
}

Relevant Logs or Screenshots:

Do you use index alias to search, if so could you check if all indices behind the alias contain the field lname.raw?

Good morning!
No, I am not using any aliases.

OK, found that if I update the “lname.raw” to “lname.keyword”, it works, and seems to still sort correctly.

However, if I try the same with “aggs”:

"aggs": {
  "total_families": {
    "terms": {
      "field": "fid.keyword",
      "size": 2000000
    }
  }
}

I’m not getting a total, coming back with 0 (zero), although I know there are values returned in fid (“fid” is the foreign key id for the family relationship). Apologies, this is a tangential issue.

Think I got it all figured out now. Basically a case of RTFM. :grin:

From the manual, found out that the “size” is now (or at least for our purposes, should be) “precision_threshold”. Once I updated, it’s working.

"aggs": {
  "total_families": {
    "cardinality": {
      "field": "fid.keyword",
      "precision_threshold": 10000
    }
  }
}