I have created some extended properties on some events, but I am trying to return all events that don't contain this extended property.
Is it possible to build this filter somehow?
I am trying to pass these filtering clauses, but none seem to work:
1. singleValueExtendedProperties/any(ep: ep/id eq '{extendedPropertyId}' and ep/value eq '')
2. singleValueExtendedProperties/all(ep: ep/id ne '{extendedPropertyId}')
3. singleValueExtendedProperties/any(ep: ep/id eq '{extendedPropertyId}' and ep/value eq null)
Just to exemplify, I have 2 possible events:
Has extended property, and it has a value
Doesn't have any extended property.
In my query, I am trying to fetch only 2, excluding any extended property
UPDATE:
I am running the following query in the /events endpoint, which works
https://graph.microsoft.com/v1.0/me/calendars/{calId}/events?startdatetime=2022-09-14T15:07:31.041Z&enddatetime=2022-09-23T15:07:31.042Z&$expand=singleValueExtendedProperties($filter=id eq 'String {43a36491-c91c-4480-b9c1-8fc61c6e0f6e} Name IntegrationId')&$filter=singleValueExtendedProperties/any(ep: ep/id eq 'String {43a36491-c91c-4480-b9c1-8fc61c6e0f6e} Name IntegrationId' and ep/value eq null)
But when running agains the /calendarView endpoint, it returns zero results
https://graph.microsoft.com/v1.0/me/calendars/{calId}}/calendarView?startdatetime=2022-09-14T15:07:31.041Z&enddatetime=2022-09-23T15:07:31.042Z&$expand=singleValueExtendedProperties($filter=id eq 'String {43a36491-c91c-4480-b9c1-8fc61c6e0f6e} Name IntegrationId')&$filter=singleValueExtendedProperties/any(ep: ep/id eq 'String {43a36491-c91c-4480-b9c1-8fc61c6e0f6e} Name IntegrationId' and ep/value eq null)
A pattern you can use is
singleValueExtendedProperties/any(ep: ep/id eq '{extendedPropertyId}' and ep/value eq null)
eg
https://graph.microsoft.com/v1.0/me/mailFolders('Inbox')/messages?$filter=singleValueExtendedProperties/any(ep: ep/id eq 'String 0x1042' and ep/value eq null)
If you want to use a Extended property within a Filter in a Calendar view then you need to expand it first (you don't need to do that when you are using the normal events endpoint). So something like
https://graph.microsoft.com/v1.0/me/calendar/calendarView?startDateTime=2022-09-01T19:00:00Z&endDateTime=2022-09-10T19:00:00Z&$select=subject&$expand=singleValueExtendedProperties($filter=id eq 'String 0x0037')&$filter=singleValueExtendedProperties/any(ep: ep/id eq 'String 0x0037' and ep/value eq 'Cloud and Mobile Working Group')
Related
Hello everyone I need to write a cypher query for a below scenario.
Given a list of strings, count the number nodes in graph where levenshtein similarity between node name property and strings from the list is more than certain thershold.
I was able to write query if we only have 1 string but I am not sure how to write a query if we have multiple strings ['string 1', 'string 2', 'string 3'].
MATCH (n:Node)
UNWIND (n.name) as name_lst
RETURN SUM(toInteger(apoc.text.levenshteinSimilarity(name_lst, 'string 1') > 0.6))
Any thoughts on how to transform the above a query if we have multiple strings.
No need to UNWIND the name as name_lst and you can use that variable directly in the APOC function.
If any of the string in the list ['string 1', 'string 2', 'string 3'] has a levSim value of > 0.6 then it will return true. Converting true to integer is 1.
Thus, getting the sum of all 1s in the result will give you the number of Nodes that has a name property with levSim value > 0.6 to any string on the list ['string 1', 'string 2', 'string 3'].
MATCH (n:Node)
RETURN SUM(toInteger(ANY(s in ['string 1', 'string 2', 'string 3']
WHERE apoc.text.levenshteinSimilarity(n.name, s ) > 0.6)))
One option is to use reduce:
MATCH (n:Node)
WITH toInteger(reduce(maxValSoFar = 0,
s IN ['string 1', 'string 2', 'string 3'] |
apoc.coll.max([maxValSoFar, apoc.text.levenshteinSimilarity(n.name, s)])) >
0.6) AS nodes
RETURN SUM(nodes)
For sample data:
MERGE (a1:Node {name:'string 1'})
MERGE (a2:Node {name:'asdss'})
MERGE (a3:Node {name:'string 2'})
MERGE (a4:Node {name:'afffs'})
MERGE (a5:Node {name:'efwetreyy'})
MERGE (a6:Node {name:'ffuumxt'})
The result is:
╒════════════╕
│"sum(nodes)"│
╞════════════╡
│2 │
└────────────┘
I'm trying to use a variable as a property name in neo4j
MATCH(e: Event {id: "123"})
MATCH(u: User {id: "456"})
MERGE (u)-[a:ACTION]->(e)
ON MATCH
SET e[a.t] = e[a.t] - 1
This gives the error:
Invalid input '[': expected an identifier character, whitespace, '{', 'x/X', node labels, a property map, a relationship pattern, '.', '(', '=' or "+=" (line 5, column 6 (offset: 96))
"SET e[a.t] = e[a.t] - 1"
While according to this forum: it should be possible.
Neo4j forum
What am I doing wrong?
Whenever we want to create a relationship dynamically, and set its properties dynamically, we should use apoc.merge.relationship function. In this function you can dynamically provide startNode, endNode, properties to set onMatch and onCreate for the relationship and some other params as well.
For your use case, you can try something like this:
MATCH(e: Event {id: "123"})
MATCH(u: User {id: "456"})
OPTIONAL MATCH (u)-[rel:ACTION]->(e)
CALL apoc.merge.relationship(
u,
"ACTION",
{},
{},
e,
apoc.map.setKey({}, toString(rel.t), rel.t - 1)
)
YIELD rel
RETURN rel;
Also, note that we have to fetch the relationship using OPTIONAL MATCH so that we can access its properties when calling the apoc function. Finally, you will also need to install APOC library for the above query to work.
The example as you pointed out in the forum uses the node['property'] form in the WHERE clause. It does not work when updating the property like you did.
For example, below query works
match (n:Actor)
where n['name'] = "Neo"
set n.age = 50
return n
Result:
n
(0:Actor {age:50, name:"Neo"})
Query took 14 ms and returned 1 rows.
Updated the graph - set 1 property
BUT THIS WILL NOT WORK:
set n['age'] = 50
Using Graph SDK, i would like to query a list that field x is in any of the values a b or c for example.
In SQL I would have
Where x in (a,b,c)
I know I can build a string like $filter = x eq a or x eq b or x eq c but it is not an elegant solution.
Anyone?
You can use IN $filter operator.
Example:
https://graph.microsoft.com/v1.0/users?$filter=mail in ('user1#xxx.com', 'user2#xxx.com')
OData in operator
MATCH (p:Product {id:'123'}) return p.$color
Where '$color' is a parameter passed from a function which generates the cypher query.
You can get the value of a property named "foo" from a p node by using the p["foo"] syntax.
So, if you have a $color parameter that has the name of a Product property, this would work:
MATCH (p:Product {id:'123'})
RETURN p[$color];
I am new to Neo4j and trying some queries on the movie database example.
I want to find all actor and movie combinations where the role name contains the word "Joe". How do I do this ?
I am able to do a query when I know the complete role name e.g. Joe Banks. The query I used for that is -
MATCH (p:Person)-[r:ACTED_IN]-(movie:Movie)
WHERE 'Joe Banks' in (r.roles)
RETURN p,movie,r.roles;
Use the list predicate function any:
MATCH (m:Movie)<-[r:ACTED_IN]-(a:Person)
WHERE any(role in r.roles WHERE role CONTAINS "Joe")
RETURN m,r,a
Edit
For case insensitive string comparison you can use the toLower function:
MATCH (m:Movie)<-[r:ACTED_IN]-(a:Person)
WHERE any(role in r.roles WHERE toLower(role) CONTAINS toLower("joe"))
RETURN m,r,a