Return specific nodes in the query result

I am trying to execute the following query.
Find sensors with temperature “6.0”^^http://www.w3.org/2001/XMLSchema#float
So in dgraph I wrote:-

{
  yo(func:has(name)) { 
	 name   		 
type@filter(eq(name,"TemperatureObservation")){
    }
    result@filter(eq(floatValue, 6.0)){
      name
      floatValue
    }

  }
}

Below is the result for the query. The first three nodes do not contain result predicate, yet they are returned. Result should only contain the nodes which have type = TemperatureObservation and result.floatValue = 6.0. What am I doing wrong?

{
  "data": {
    "yo": [
 {
        "name": "MeasureData_WindDirection_4UT01_2004_8_9_18_30_00"
      },
      {
        "name": "Observation_WindGust_4UT01_2004_8_10_14_50_00"
      },
      {
        "name": "Observation_AirTemperature_4UT01_2004_8_13_13_35_00"
      },
      {
        "name": "Observation_WindGust_4UT01_2004_8_10_6_55_00",
        "result": [
          {
            "name": "MeasureData_WindGust_4UT01_2004_8_10_6_55_00",
            "floatValue": 6
          }
        ]
      }

You are using “has” func in the first level. This query returns any node who has the predicate “name”.

The part

type@filter(eq(name,"TemperatureObservation")){
    }

is doing nothing. It is isolated.

The nested query in the result edge is returning what you want.

If you wanna use this query anyway. Add the @cascade directive

e.g

{
  yo(func:has(name))  @cascade { 
	 name   		 
type@filter(eq(name,"TemperatureObservation")) { 
# If the node doesn't have this nested connection. It will return empty.
# So, remove it if you need tho.
    uid
    }
    result@filter(eq(floatValue, 6.0)){
      name
      floatValue
    }
  }
}
1 Like