question

nithishreddyminupuri-8171 avatar image
0 Votes"
nithishreddyminupuri-8171 asked AnuragSharma-MSFT answered

can you model a document as one of the property in a vertex in Gremlin DB ?

property("States", {"DeviceCount":"12","SC_ItemStatus":"2","SC_ItemWarningStatus":"0","SC_SStandardPerc":"1"}).

How do you query it if you wanted to find DeviceCount? I know that i can model it using another vertex to state and relationship between first vertex and states. Checking if there is a alternative to it and wanted to know how that affects different reads?


azure-cosmos-db
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AnuragSharma-MSFT avatar image
0 Votes"
AnuragSharma-MSFT answered

Hi @nithishreddyminupuri-8171, thanks for replying back.

<Writing it as another answer as word limit is crossing 1600 characters>

Id is unique identifier which is assigned to every item in Azure Cosmos DB while these items are created. Index concept is similar to what we have on other databases .Indexes are created by default in Cosmos DB on every property and they help us in writing the efficient and less expensive queries. This means if we exclude any property from index then the same query could take more RUs or more time to execute compared to the indexed properties which would then add to the cost. Now we might not notice any change for few documents but when the documents go to millions or more this would significantly impact the cost.

For retrieving all the properties lets take below examples:
Here we are adding 2 vertex:

 g.addV('person').property('id', 'mary').property('firstName', 'Mary').property('lastName', 'Andersen').property('age', 39).property('pk', 'pk')
 g.addV('person').property('id', 'steve').property('firstName', 'Steve').property('lastName', 'Wood').property('age', 40).property('pk', 'pk')

So if we run below query we will get both these with all the properties:

 g.V().hasLabel('person').has('age', gt(38))

Result:

131851-image.png

Same way we can write more queries depending upon the structure of our document.

Please let me know if this helps or we can discuss further on the same.



Please don't forgot to click on accept it as answer button 131823-image.png wherever the information provided helps you. This can be beneficial to other community members as well..





image.png (36.7 KiB)
image.png (8.7 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AnuragSharma-MSFT avatar image
0 Votes"
AnuragSharma-MSFT answered nithishreddyminupuri-8171 edited

Hi @nithishreddyminupuri-8171, welcome to Microsoft Q&A forum.

We can add a vertex with JSON object as below. I just used couple of attribute in JSON object, you can add as per requirements.

 g.addV('person').property('States','{\"DeviceCount\":\"15\",\"SC_ItemStatus\": \"6\"}').property('pk', 'pk')

Then we can query it something like this. Here we are doing a contain search on value.

 g.V().hasLabel('person').has('States', TextP.containing('DeviceCount'))
    
 OR
    
 g.V().hasLabel('person').has('States', TextP.containing('"DeviceCount":"15",'))

Now as we are using a contain query it is more expensive than a direct query.

Direct Query:
131465-image.png

Contain Query:
131531-image.png

We notice the contain query is more expensive than the other query. This search is done on couple of vertices but if we have more it will get more expensive. Just to add, Azure Cosmos adds default indexes on every property.

As per me I would recommend if we create another vertex to state and then have a relationship as you mentioned. It would be easier to manage as well.

Please let me know if this helps or else we can discuss further on the same.


Please don't forgot to click on accept it as answer button 130202-image.png wherever the information provided helps you. This can be beneficial to other community members as well.





image.png (18.5 KiB)
image.png (14.9 KiB)
image.png (6.9 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi Anurag,

I see that a specific id is created for every property. How does that imply on cost ? I also knew that I can create mutiple properties in Gremlin by using .properties and has value and then properties. How to retrieve these multiple values.

Example:
g.addV("item").
property("id", '001').
properties('SEL').hasValue('bf6').
property('name', 'ajit').
property('age', 23)

How to retrieve all the meta properties or all properties


0 Votes 0 ·