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.

Slow Cypher Query using CONTAINS and relationships attributes

In our database we have a lot of nodes of type "Document"

MATCH (n:Document) RETURN COUNT(n) AS count

Returns

count
231266485

When queries are made using the operator = the response is fast

But we need to search only nodes containing number 8981231 and having relations with the following attributes:

MATCH (n:Document) WHERE (n.number CONTAINS '8981231') WITH n WHERE ((n)-[{someAttribute: 'linkAnalisysTest'}]-()) RETURN n.number LIMIT 10

Time to complete query

Started streaming 2 records after 10196 ms and completed after 44930 ms.

Explain (edited)

1 ACCEPTED SOLUTION

HI guys

We try another approach and works!!!

CALL db.index.fulltext.queryNodes('document', '*95587*') yield node AS n WITH n WHERE ((n)-[{someAttribute: 'linkAnalisys'}]-()) RETURN n.number LIMIT 10

View solution in original post

5 REPLIES 5

Can you run a PROFILE instead, and also expand all elements of the query plan? It's the double-down arrow in the lower right of the result pane.

Hi! thanks for reply

Sorry for my mistake i just attached the wrong image

Explain (Correct) (Type of node is "cpf" i put "Document" to facilitate understanding

Profile

My guess is because the database can't do an exact match, reading from the beginning and moving on when the beginning of the attribute isn't a match, but instead the database has to examine the whole string of the attribute for the CONTAIN operation, you're seeing more db hits? This is only speculation.

Questions:

  • Can you provide the Profile for both the = and the CONTAINS queries so we can compare the two explanations?
  • Do you have any regular indexes specified on this attribute?
  • Have you looked at specifying a Full Text Search index on this data. If you're doing a fuzzy contains search, the Lucene index would be worth looking into.

Hi mike! thanks for reply

Answer the questions

  • Indexes
    Yes we have indexes in attributes (cpf and "someAttribute")

  • Full Text Search
    We try use Full text search but the result is the same (slow query)

  • Profile (=)

  • Profile (CONTAINS)

HI guys

We try another approach and works!!!

CALL db.index.fulltext.queryNodes('document', '*95587*') yield node AS n WITH n WHERE ((n)-[{someAttribute: 'linkAnalisys'}]-()) RETURN n.number LIMIT 10