Need help with nested Properties Gremlin query

48 views
Skip to first unread message

mahima

unread,
Nov 10, 2022, 10:04:18 AM11/10/22
to Gremlin-users
Hi, 

g.addV('object_model').property('s_objectId', '20gh').as('object_model').  
  addV('properties').property('s_objectId', '20gh').as("properties").  
  addV('s_model').property('s_objectId', '20gh').property('model','modelId').as('s_model').
  addV('s_objectId').property('s_objectId', '20gh').as('s_objectId').  
  addV('p_settings').property('s_objectId', '20gh').as('p_settings').  
  addV('digitalInput').property('s_objectId', '20gh').as('digitalInput').
  addV('digitalInput2').property('s_objectId', '20gh').as('digitalInput2').
  addV('Input1').property('s_objectId', '20gh').property('value', 12).as('Input1').
  addV('Input2').property('s_objectId', '20gh').property('value', 17).as('Input2').
  addV('Input3').property('s_objectId', '20gh').property('value', 12).as('Input3').
     addE('property').from('object_model').to("properties").
     addE('model').from("properties").to('s_model').
     addE('object_Id').from("properties").to('s_objectId').
     addE('settings').from('properties').to('p_settings').
     addE('digitalInput').from('p_settings').to('digitalInput').
     addE('digitalInput2').from('p_settings').to('digitalInput2').
     addE('Input1').from('digitalInput').to('Input1').
     addE('Input2').from('digitalInput').to('Input2').
     addE('Input3').from('digitalInput2').to('Input3')
     
     
This is the insertion query that I am running.
I want the output in below format if user search for settings(which is a nested property node)


 "properties": {
    "settings": {
      "DigitalInput": {
        "Input1": {
              "value": 12
        },
        "Input2": {  
          "nTransIn2": {
            "tagName": {
              "value": 17
            }
          }
        },
        "Input3": {
          "nTransIn3": {
            "tagName": {
              "value": 12
            }
          }
        }
      }
    }
    }
   
    - I have tried quite a few queries but I am getting output as below
   
    g.V().has( 'object_model','s_objectId',within('20gh')).out('property').out('settings').emit().repeat(out()).properties().tree()

   
    [
  [
    {
      "key": {
        "id": 7904,
        "label": "object_model"
      },
      "value": [
        {
          "key": {
            "id": 7907,
            "label": "properties"
          },
          "value": [
            {
              "key": {
                "id": 7917,
                "label": "p_settings"
              },
              "value": [
                {
                  "key": {
                    "id": 7920,
                    "label": "digitalInput"
                  },
                  "value": [
                    {
                      "key": {
                        "id": 7922,
                        "value": "20gh",
                        "label": "s_objectId"
                      },
                      "value": []
                    },
                    {
                      "key": {
                        "id": 7926,
                        "label": "Input1"
                      },
                      "value": [
                        {
                          "key": {
                            "id": 7928,
                            "value": "20gh",
                            "label": "s_objectId"
                          },
                          "value": []
                        },
                        {
                          "key": {
                            "id": 7929,
                            "value": 12,
                            "label": "value"
                          },
                          "value": []
                        }
                      ]
                    },
                    {
                      "key": {
                        "id": 7930,
                        "label": "Input2"
                      },
                      "value": [
                        {
                          "key": {
                            "id": 7932,
                            "value": "20gh",
                            "label": "s_objectId"
                          },
                          "value": []
                        },
                        {
                          "key": {
                            "id": 7933,
                            "value": 17,
                            "label": "value"
                          },
                          "value": []
                        }
                      ]
                    }
                  ]
                },
                {
                  "key": {
                    "id": 7923,
                    "label": "digitalInput2"
                  },
                  "value": [
                    {
                      "key": {
                        "id": 7925,
                        "value": "20gh",
                        "label": "s_objectId"
                      },
                      "value": []
                    },
                    {
                      "key": {
                        "id": 7934,
                        "label": "Input3"
                      },
                      "value": [
                        {
                          "key": {
                            "id": 7936,
                            "value": "20gh",
                            "label": "s_objectId"
                          },
                          "value": []
                        },
                        {
                          "key": {
                            "id": 7937,
                            "value": 12,
                            "label": "value"
                          },
                          "value": []
                        }
                      ]
                    }
                  ]
                },
                {
                  "key": {
                    "id": 7919,
                    "value": "20gh",
                    "label": "s_objectId"
                  },
                  "value": []
                }
              ]
            }
          ]
        }
      ]
    }
  ]
]
   

 Any help with the formation of query is appreciated.

Thanks and Regards, 
Mahima

Prabu L

unread,
Dec 15, 2022, 8:00:48 AM12/15/22
to Gremlin-users
Hi ,

Can you try something like this ?
g.V().properties(' settings  ').has('value','<<your_value>>')

Hope this helpful

Reply all
Reply to author
Forward
0 new messages