Repository navigation
How to create an index on embedded properties in a Class #10820
|
Class name is Category and below is the JSON structure. I want to create an composite unique index on category, details.uniqueproperites.uniquekey1, details.uniqueproperites..uniquekey2 Please let me know how to create index |
Replies: 2 comments 1 reply
|
An automatic composite index cannot index those arbitrary nested JSON paths directly. OrientDB builds automatic indexes from schema properties of the indexed class; Also note that the values in the sample are one level deeper than the paths in the question: the actual paths end in The reliable design is to materialize the values that define uniqueness as schema properties on CREATE PROPERTY Category.category STRING;
CREATE PROPERTY Category.uniqueKey1 STRING;
CREATE PROPERTY Category.uniqueKey2 STRING;
CREATE INDEX Category_unique_keys
ON Category (category, uniqueKey1, uniqueKey2)
UNIQUE;A record would then contain the indexable values, for example: {
"category": "test",
"uniqueKey1": "val1",
"uniqueKey2": "val2",
"description": "desc",
"details": {
"uniqueproperites": {
"uniquekey1": {"value": "val1"},
"uniquekey2": {"value": "val2"}
}
}
}You can either make those top-level fields the source of truth or keep them synchronized with the nested representation in your write path. If you control the model, removing the duplicate nested representation is safer because it cannot drift. The official After creation, check both the constraint and planner use with a duplicate insert test and If this answers the question, please mark it as accepted so future readers do not spend time trying unsupported nested-path index syntax. |
|
Hi, |
An automatic composite index cannot index those arbitrary nested JSON paths directly. OrientDB builds automatic indexes from schema properties of the indexed class;
details.uniqueproperites.uniquekey1.valueis not a property ofCategorythat the index definition can maintain.Also note that the values in the sample are one level deeper than the paths in the question: the actual paths end in
.value(and there is a double..beforeuniquekey2in the question).The reliable design is to materialize the values that define uniqueness as schema properties on
Categoryand index those: