Skip to content

Creating Index on specific property #954

Closed

Description

@Munmud

Suppose I have created nodes as follow

SELECT * from cypher('munmud', $$
CREATE 
(:Movie {id: 'movie1', name: 'The Shawshank Redemption', imdbRank : 25}),
(:Movie {id: 'movie2', name: 'The Godfather', imdbRank : 60}),
(:Movie {id: 'movie3', name: 'The Dark Knight', imdbRank : 100})
$$) as (V agtype);

Now I want to create index only with the imdbRank without using other property. How can I do that ?

I know I can use the label to create index as follow

CREATE INDEX index_name
ON graph_name."Label" USING gin (properties);

But that will use all the property which is not what I want. I want only to use index with specific property.

Activity

  1. added
    question
    on May 31, 2023
  2. Chidera6 commented on May 31, 2023

    @Chidera6

    To create an index with a specified property, the exact property will be accessed using the JSONB operator ->, the syntax will look like this.
    CREATE INDEX imdb ON munmud."Movie" USING gin ((properties->'imdbRank'));

  3. talhahahae commented on May 31, 2023

    @talhahahae

    I am also confused in this.
    I think apache age does not support creating index on a specific property. Once you create an index it would create index on all the labels. Which means if you create an index it will contain all the properties of the labeled nodes.

  4. dukeofhazardz commented on May 31, 2023

    @dukeofhazardz

    Like @Chidera6 said, the query creates a GIN index on the imdbRank property of the Movie nodes in the munmud graph. The GIN index is a versatile index structure suitable for efficiently querying and filtering JSONB data, which is the data type of the properties column in this case.
    You can use the query SELECT * FROM pg_indexes WHERE tablename = 'Movie'; to retrieve information about the indexes associated with the table named Movie in the 'munmud' schema.

    The output should be something like this:

     schemaname | tablename | indexname | tablespace |                                      indexdef
    
    ------------+-----------+-----------+------------+------------------------------------------------------------------------------------
     munmud     | Movie     | imdb      |            | CREATE INDEX imdb ON munmud."Movie" USING gin (((properties -> 'imdbRank'::text)))
    (1 row)
    

    You can see the indexname 'imdb', the indexdef column in the result shows the definition of the index, including the index type (gin in this case) and the expression used for indexing (((properties -> 'imdbRank'::text))).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    question

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions