Multi-valued field indexing

Is it possible to apply an index to a list of (string) values, so that you can efficiently look up "all nodes with a list property that contains X".

I have tried creating the index, and adding a list of strings, but any cypher search I do either returns nothing, or the profile shows the results are obtained via a label scan and not the index.

If it is possible:
a) Does the CREATE INDEX statement need to do anything special?
b) What does the MATCH statement look like?



Currently this kind of lookup isn't supported with schema indexes. We would advise remodeling these as connected nodes to your main node.

For example, if you had something like:

(:Sentence {id:12345, words:['sphynx', 'of', 'black', 'quartz', 'judge', 'my', 'vow']})

We would advise you to remodel such that:

(:Sentence {id:12345})-[:HAS_WORD]->(:Word {word:'sphynx'})

and so forth with a separate :Word node per word, and an index on :Word(word) for quick lookup.

Your :Word nodes would be reused with other :Sentence nodes so you could find similar sentences with the same words:

MATCH (w:Word)<-[:HAS_WORD]-(s:Sentence)
WHERE w.word = 'quartz'
1 Like

Array indexes only find the full array.
You can use a manual index via APOC for that (which indexes each array entry),
or better the new fulltext index for 3.5.

Thanks. APOC was going to be plan B, but the additional manual index maintenance was a headache I didn't really want for a solution to an edge case that I'm hoping will never happen. I'm going to give 3.5 a try - it's about time I took a look.

I assume that the Neo4JRule TestRule code (Java) for 3.5 supports this new indexing for my testing entertainment?

The new indexes are managed via procedures, so i don't see why not.

I tried searching but it's not clear to me if APOC full text search can work on an list of strings. It would be nice if it did.

E.g. If I have a person with nicknames, can I do an APOC full text index and search on the list of nicknames? (I understand the built-in indexing property indexing won't work.)

CREATE (p:Person {name:"Elizabeth", nicknames: [
  "Lizzy", "Liz", "Beth", "Betsy"]})

Thanks in advance.

The old 3.x indexes supported multi-value arrays/lists as properties. None of the current indexes do. There are a number of feature requests for it but nothing has been decided yet.

Is that true for both standard indexing and full text indexing?


Yes, true for both types of indexes

Thanks, any updates on these feature requests?

No changes at this time on this one, though there are other index changes coming down the pipeline.