cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

How do export indexes to json file?

tms
Graph Buddy

Please forgive my Cypher newbie ignorance -- even after a year and a half, I just do not grok how Cypher returns results.

The task at hand is to export a .json file whose contents are the result of SHOW INDEXES. Presumably I can use the same approach to create another .json file containing the result of SHOW CONSTRAINTS.

I sort-of understand how to use MATCH and MERGE to provide temporary variable names that I can pass along using WITH and RETURN. I find nothing in the documentation for SHOW INDEXES that indicates the type and use of its results.

I'm hoping that one of you can provide a Cypher string that emits the results of SHOW INDEXES to a JSON file. I've tried a few alternatives and I clearly don't understand what's going on.

1 REPLY 1

Hi tms,

I use this to output my indexes in a json format, I then save the results to a .json file in my code, you can also just copy the results and paste them in a json file.

I am only "yielding" the fields that I found useful, but there are a few others that you could pull.

call db.indexes() yield name, type, labelsOrTypes, properties
WITH * 
ORDER BY labelsOrTypes[0]
WITH COLLECT({name:name, type:type, labelsOrTypes:labelsOrTypes, properties:properties}) as results
return apoc.convert.toJson(results) as results

The results look like this:

[
    {
        "name": "my_index_name",
        "labelsOrTypes": [
            "MyNodeLabel"
        ],
        "type": "BTREE",
        "properties": [
            "my_indexed_prop"
        ]
    }
]

Hope that helps