Atlas Search: Can't search or sort on a nested number field

Hi, I’m having trouble with searching and sorting documents on a nested number field and was hoping someone could help.

My documents have a field from_price, and it has a subfield amount, which is a non-integer number field. I’ve indexed it as a Number type with dynamic mapping disabled (search index snippet below) but I still can’t get sorting, or the range operator to work. However, sorting and range do both work on a top-level field (popularity, an integer in this case).

When trying to sort, the documents returned are completely unchanged whether I put sort: {"from_price.amount": 1} or sort: {"from_price.amount": -1}.
When using the range operator with from_price.amount I don’t get any documents returned at all.
Neither of these queries results in an error.

Below are a snippet of the search index and two search queries, one for sorting and the other for the range operator. In both queries, when changing from_price.amount to popularity both sort and range work. I’m aware that I can use $sort rather than the Atlas-specific sort, but I’m not sure if there’s a similar workaround for the range operator (specifically gte and lte).


Search index snippet (I have other fields indexed but this is what from_price, and popularity look like):

"mappings": {
  "dynamic": false,
  "fields": {
    "from_price": {
      "fields": {
        "amount": {
          "type": "number"
        }
      },
      "type": "document"
    },
    "popularity": {
      "type": "number"
    }
  }
}

Example aggregation for range operator:

[
  {
    $search: {
      index: "search",
      compound: {
        must: [
          {
            range: {
              gte: 1,
              path: "from_price.amount",
            },
          },
          {
            text: {
              query: ["US", "EU", "AE", "GB"],
              path: "country_code",
            },
          },
        ],
      },
    },
  },
]

Example aggregation for sort operator:
[
  {
    $search: {
      index: "search",
      compound: {
        must: [
          {
            text: {
              query: ["US", "EU", "AE", "GB"],
              path: "country_code",
            },
          },
        ],
      },
      sort: {"from_price.amount": 1}
    },
  },
]

Hi @Alex_Samarin, can you share a sample document? I am going to test it on my side. Also when you say “non-integer number field”, can you elaborate? That may be the issue.

Hi @Elle_Shwer, thanks for taking a look.
After you mentioned the field data type I took a look and turns out popularity is a double, whereas from_price.amount is Decimal128. I changed a few documents to be double everywhere and both range and sort started working.
I’ve now found a list of data types unsupported by Atlas Search so hopefully I’ll avoid anything similar in the future.
Thanks very much!

Yep, that was the problem! If you are interested in eventual support for Decimal128 - feel free to vote for it here.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.