Using "orderdesc" & "orderasc" returns nothing or incorrect result

I have a predicate like this:

product.price: int @index(int) .

In my database, most of the products have zero(0) value for this predicate. When I use “orderdesc” or “orderasc” in my query, dgraph just returns products that are not zero for this predicate, but when I delete these functions from my query, dgraph returns result correctly. Is this a bug or I did not understand these functions correctly?

Hi Samadadi,

It seems to me that everything is normal, see the tests below. Something you are doing is wrong, please give more details of what you are doing.

Mutation

{
  set {
    _:Test <product.price> "0" .
    _:Test2 <product.price> "0" .
    _:Test3 <product.price> "2" .
    _:Test4 <product.price> "4" .
    _:Test5 <product.price> "88" .
    _:Test6 <product.price> "9" .
    _:Test7 <product.price> "0" .
    _:Test8 <product.price> "0" .
    _:Test9 <product.price> "200" .
    _:Test10 <product.price> "4" .
    _:Test11 <product.price> "8" .
    _:Test12 <product.price> "9" .
    _:Test13 <product.price> "0" .
    _:Test14 <product.price> "0" .
    _:Test15 <product.price> "25" .
    _:Test16 <product.price> "4" .
    _:Test17 <product.price> "8" .
    _:Test18 <product.price> "90" .
    _:Test19 <product.price> "90" .
  }
}

Query 1


{
  prices (func: has(product.price), orderdesc:product.price ){
    uid
    product.price
  }
}

Result

{
  "data": {
    "prices": [
      {
        "uid": "0xd",
        "product.price": 200
      },
      {
        "uid": "0x1",
        "product.price": 90
      },
      {
        "uid": "0x10",
        "product.price": 90
      },
      {
        "uid": "0x2",
        "product.price": 88
      },
      {
        "uid": "0xa",
        "product.price": 25
      },
      {
        "uid": "0x3",
        "product.price": 9
      },
      {
        "uid": "0x9",
        "product.price": 9
      },
      {
        "uid": "0x6",
        "product.price": 8
      },
      {
        "uid": "0xf",
        "product.price": 8
      },
      {
        "uid": "0xe",
        "product.price": 4
      },
      {
        "uid": "0x11",
        "product.price": 4
      },
      {
        "uid": "0x13",
        "product.price": 4
      },
      {
        "uid": "0x7",
        "product.price": 2
      },
      {
        "uid": "0x4",
        "product.price": 0
      },
      {
        "uid": "0x5",
        "product.price": 0
      },
      {
        "uid": "0x8",
        "product.price": 0
      },
      {
        "uid": "0xb",
        "product.price": 0
      },
      {
        "uid": "0xc",
        "product.price": 0
      },
      {
        "uid": "0x12",
        "product.price": 0
      }
    ]
  }

Query 1


{
  prices (func: has(product.price), orderasc:product.price ){
    uid
    product.price
  }
}

Result

{
  "data": {
    "prices": [
      {
        "uid": "0x4",
        "product.price": 0
      },
      {
        "uid": "0x5",
        "product.price": 0
      },
      {
        "uid": "0x8",
        "product.price": 0
      },
      {
        "uid": "0xb",
        "product.price": 0
      },
      {
        "uid": "0xc",
        "product.price": 0
      },
      {
        "uid": "0x12",
        "product.price": 0
      },
      {
        "uid": "0x7",
        "product.price": 2
      },
      {
        "uid": "0xe",
        "product.price": 4
      },
      {
        "uid": "0x11",
        "product.price": 4
      },
      {
        "uid": "0x13",
        "product.price": 4
      },
      {
        "uid": "0x6",
        "product.price": 8
      },
      {
        "uid": "0xf",
        "product.price": 8
      },
      {
        "uid": "0x3",
        "product.price": 9
      },
      {
        "uid": "0x9",
        "product.price": 9
      },
      {
        "uid": "0xa",
        "product.price": 25
      },
      {
        "uid": "0x2",
        "product.price": 88
      },
      {
        "uid": "0x1",
        "product.price": 90
      },
      {
        "uid": "0x10",
        "product.price": 90
      },
      {
        "uid": "0xd",
        "product.price": 200
      }
    ]
  }

Hi, thank you for your response. I found the problem. The problem was in my json encoding section. I had “omitempty” tag in my struct definition. So as a result there was no predicate related to most of the products. So the query could not return such products.