Author Archives: Raghavendar T S

Neo4j Query Tutorial – MATCH and MERGE

Neo4j Query Tutorial - MATCH and MERGE

Neo4j Query Tutorial – MATCH and MERGE

Example 1:

Match two nodes and create a relationship between them.

MATCH (person1:LABEL{id:'1234'}),(person2:LABEL{id:'5678'})
MERGE (person1)-[r:FRIEND]-(person2)

Example 2:

Match two nodes and create/update a relation between them. Optionally set properties to the nodes or relationships with ON CREATE SET or ON MATCH SET. Use r+={property:’value’} to add properties or update existing properties.

MATCH (user1:USER{id:'123'}),(user2:USER{id:'456'}) 
MERGE (user1)-[r:FRIEND]-(user2)
ON CREATE SET
    r={createdDate:'01-04-2016',updatedDate:'01-04-2016'}
ON MATCH SET 
    r={createdDate:'01-04-2016',updatedDate:'01-04-2016'}
RETURN user1,user2

Example 3:

MATCH a node and pass the required node or relationship to next level of processing using WITH option.

MATCH (user1:USER{id:'123'})
WITH user1
MATCH (user2:USER{id:'456'})
WITH user1,user2
MERGE (user1)-[r:FRIEND]-(user2)
ON CREATE SET
    r={createdDate:'01-04-2016',updatedDate:'01-04-2016'}
ON MATCH SET 
    r={createdDate:'01-04-2016',updatedDate:'01-04-2016'}
RETURN user1,user2,r

Example 4:

Update out going releationships for a node

MATCH (user1:USER{id:'123'})-[r]-()
SET 
    r.property='value'
RETURN user1

Example 5:

Use a property value of a one object/node/relationship with another object/node/relationship.

MATCH (user1:LABEL{id:'123'})-[r]-(user2:LABEL{property:user1.propertyValue})
SET 
   r={someProperty:'value'}
RETURN user1.id,r.id,user2.id

Example 6:

MATCH (n:LABEL) WHERE n.property='value'
RETURN n

Elasticsearch – Date/Time(String) Add/Subtract Duration – Days,Months,Years,Hours,Minutes,Seconds

Elasticsearch - DateTime(String) Add/Subtract Duration - Days,Months,Years,Hours,Minutes,Seconds

Elasticsearch – Date/Time(String) Add/Subtract Duration – Days,Months,Years,Hours,Minutes,Seconds

Sample Query :

POST /test/test/_search
{
    "query": {
        "filtered": {
            "filter": {
                "bool": {
                    "must": [{
                        "range": {
                            "dateOrTimeAttribute": {
                                "from": "16:31:15",
                                "to": "16:31:15||+10m"
                            }
                        }
                    }]
                }
            }
        }
    }
}

Examples:

  • “16:31:15||+10m”
  • “16:31:15||+1d”
  • “2016-02-02||-1M”

 

Java – Read/Parse Command Line Arguments/Options

Java - Read/Parse Command Line Arguments/Options

Java – Read/Parse Command Line Arguments/Options

Maven Dependency :

<dependency>
    <groupId>commons-cli</groupId>
    <artifactId>commons-cli</artifactId>
    <version>1.2</version>
</dependency>

Sample Java Program :

package test;

import org.apache.commons.cli.BasicParser;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
public class Test
{
    public static void main(String[] args) {

        //Define Options
        Options options = new Options();

        //Option Name - option1
        //Has input value - true
        options.addOption("option1", true, "Option 1 Description");

        //Option Name - option2
        //Has input value - false
        options.addOption("option2", false, "Option 2 Description");

        CommandLineParser parser = new BasicParser();
        CommandLine cmd = null;

        try {
            cmd = parser.parse(options, args);
        } catch (ParseException e1) {
            e1.printStackTrace();
        }

        System.out.println(cmd.hasOption("option1"));
        System.out.println(cmd.hasOption("option2"));

        System.out.println(cmd.getOptionValue("option1"));
        System.out.println(cmd.getOptionValue("option2"));

    }
}

Output :

Consider we execute the sample Java program with following arguments

java Test -option1 option1Value -option2

true
true
option1Value
null

option2 value is null because it does not takes input values which is defined using the Options class.

Java JConsole – Local Process List Empty – Solved

JAVA JCONSOLE – LOCAL PROCESS LIST EMPTY – SOLVED.png

Java JConsole – Local Process List Empty – Solved

JConsole or  Java Monitoring and Management Console

  1. Open command prompt
  2. Execute the command echo %TMP%
  3. Now you will get a path to a folder where temporary files are stored. E.g. C:\Users\Username\AppData\Local\Temp
  4. Go to that folder
  5. Remove the folder named hsperfdata_USERNAME
  6. Restart JConsole application and now you will have the list of currently running Java processes in the local process list
  7. You can also the JConsole directly from command line using the command  jconsole PROCESS_ID
  8. Enjoy !!!