Search code examples
ignite

Is it possible to create an index on a multi-value field in Ignite?


In some database systems you can have indices on a multi-valued field. For instance, in MongoDB, if your documents have an array field like this

{
    "authors": ["John", "Mary"],
    ....
}

then you could create an index on authors field and this index would speed up queries on this authors field.

In Ignite, using key-value APIs, you could put anything in a cache. Value's fields could contain scalar values, collections, objects. You could create an index, but all the examples I could find in the documentation always deal with scalar fields.

Let's imagine that a value I store in Ignite has a field of type List<String> and I'd like to find such a value by any element of the list. Would it be possible to have an index on it to speed up search? (To be honest, I doubt that as there does not seem to exist even a way to write such a query using SQL, but who knows...)


Solution

  • The way you would do that in Ignite is to normalise the data, that is, you'd have two caches with a one-to-many relationship. Then you'd use SQL to query the values in the list.

    To make it efficient, you'd need to use an affinity key to make sure the "many" side was on the same machine as the "one."