Skip to main content
Solved

Unable to filter the edges in an efficient manner using model/instances/query endpoint

  • January 15, 2025
  • 2 replies
  • 30 views

Hello
We have Flexible model which has Entity view and then a property named parent refers to Entity back as an edge. Now our user sends us an query to get all the entities say whose name is “SomeString”. And then we construct a query as below, but it errors out.

{
    "with": {
        "Entity": {
            "nodes": {
                "filter": {
                                    "and": [
                  {
                    "matchAll": {}
                  },
                   { "hasData": [
                        {
                            "type": "view",
                            "space": "slb-pdm-dm-governed",
                            "externalId": "Entity",
                            "version": "1_7"
                        }
                    ]},
                                        {"or": [
  {
    "and": [
      {
        "nested": {
          "scope": [
            "slb-pdm-dm-governed",
            "Entity/1_7",
            "parent"
          ],
          "filter": {
            "in": {
              "property": [
                "node",
                "name"
              ],
              "values": [
                "SomeString"
              ]
            }
          }
        }
      }
    ]
  }
]}
                                    ]
                },
                "chainTo": "destination",
                "direction": "outwards"
            }
        },
        "parent.Entity": {
            "nodes": {
                "from": "Entity",
                "filter": {
                    "and": [
                        {
                            "hasData": [
                                {
                                    "type": "view",
                                    "space": "slb-pdm-dm-governed",
                                    "externalId": "Entity",
                                    "version": "1_7"
                                }
                            ]
                        },
                        {
                            "in": {
                                "property": [
                                    "node",
                                    "externalId"
                                ],
                                "values": [
                                    "56debee29ada4609beff4c12bb9244a3"
                                ]
                            }
                        }
                    ]
                },
                "through": {
                    "source": {
                        "space": "slb-pdm-dm-governed",
                        "externalId": "Entity",
                        "version": "1_7",
                        "type": "view"
                    },
                    "identifier": "parent"
                },
                "chainTo": "destination",
                "direction": "outwards"
            }
        }
    },
    "select": {
        "Entity": {
            "sources": [
                {
                    "source": {
                        "space": "slb-pdm-dm-governed",
                        "externalId": "Entity",
                        "version": "1_7",
                        "type": "view"
                    },
                    "properties": [
                        "name",
                        "parent"
                    ]
                }
            ]
        },
        "parent.Entity": {
            "sources": [
                {
                    "source": {
                        "space": "slb-pdm-dm-governed",
                        "externalId": "Entity",
                        "version": "1_7",
                        "type": "view"
                    },
                    "properties": [
                        "name"
                    ]
                }
            ]
        }
    }
}

with an error- {
    "error": {
        "code": 400,
        "message": "Invalid in filter with property reference [node, name]. Property reference must have the format [<space>, <externalId|externalId/version>, <property>] or [<node|edge>, <property>]. Valid base properties are [space, externalId, createdTime, lastUpdatedTime, type] for node, and [space, externalId, createdTime, lastUpdatedTime, startNode, endNode, type] for edge."
    }
}


As we get the name from the user as input we really dont know about the external Id at that point in time. How do we go with this ? 

Other way we can do is we dont pass edge filter in Views filter part rather we pass it in edges filter, but then we get all the nodes available and then we have to traverse through all the nodes to find out relevant node. Can you help here?

Regards,
Neeraj B 

Best answer by Arild Eide

Hi ​@Neerajkumar Bhatewara 

 

Thanks for reaching out!

Specifically, to the error message your are facing: When filtering by value of some property that you have defined on the view, the query also needs to refer to the view that has property in question. This is different from the base properties like space and externalId, like you are doing in the second filter.

 

So I think the filter should be something like:
"filter": {"in": {"property": ("slb-pdm-dm-governed", "Entity/1_7", "name"), "values": ["SomeString"]}},
 

Hope this helps.

 

Thanks

 

Arild Eide

View original
Did this topic help you find an answer to your question?

2 replies

Forum|alt.badge.img
  • Seasoned Practitioner
  • 38 replies
  • Answer
  • January 16, 2025

Hi ​@Neerajkumar Bhatewara 

 

Thanks for reaching out!

Specifically, to the error message your are facing: When filtering by value of some property that you have defined on the view, the query also needs to refer to the view that has property in question. This is different from the base properties like space and externalId, like you are doing in the second filter.

 

So I think the filter should be something like:
"filter": {"in": {"property": ("slb-pdm-dm-governed", "Entity/1_7", "name"), "values": ["SomeString"]}},
 

Hope this helps.

 

Thanks

 

Arild Eide


Thanks ​@Arild Eide , this works. Appreciate.

Final query that works
{
    "with": {
        "Entity": {
            "nodes": {
                "filter": {
                                    "and": [
                  {
                    "matchAll": {}
                  },
                   { "hasData": [
                        {
                            "type": "view",
                            "space": "slb-pdm-dm-governed",
                            "externalId": "Entity",
                            "version": "1_7"
                        }
                    ]},
                                        {"or": [
  {
    "and": [
      {
        "nested": {
          "scope": [
            "slb-pdm-dm-governed",
            "Entity/1_7",
            "parent"
          ],
          "filter": {
            "in": {
              "property": [
                "slb-pdm-dm-governed", "Entity/1_7", "name"
              ]
,
              "values": [
                                "SomeString"
              ]
            }
          }
        }
      }
    ]
  }
]}
                                    ]
                },
                "chainTo": "destination",
                "direction": "outwards"
            }
        },
        "parent.Entity": {
            "nodes": {
                "from": "Entity",
                
                "through": {
                    "source": {
                        "space": "slb-pdm-dm-governed",
                        "externalId": "Entity",
                        "version": "1_7",
                        "type": "view"
                    },
                    "identifier": "parent"
                },
                "chainTo": "destination",
                "direction": "outwards"
            }
        }
    },
    "select": {
        "Entity": {
            "sources": [
                {
                    "source": {
                        "space": "slb-pdm-dm-governed",
                        "externalId": "Entity",
                        "version": "1_7",
                        "type": "view"
                    },
                    "properties": [
                        "name",
                        "parent"
                    ]
                }
            ]
        },
        "parent.Entity": {
            "sources": [
                {
                    "source": {
                        "space": "slb-pdm-dm-governed",
                        "externalId": "Entity",
                        "version": "1_7",
                        "type": "view"
                    },
                    "properties": [
                        "name"
                    ]
                }
            ]
        }
    }
}

Neeraj B


Reply


Cookie Policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie Settings