How to enable Hash Index Type for embedded OrientDB Graph Databases? - orientdb

By default OrientDB is using the "SB-Tree" index¹. Is it somehow possible to change the used index type to "Hash" through Java API Calls?
I was unable to find a way to change the selected index type.
[1] http://orientdb.com/docs/2.1/Indexes.html

From Graph API, you can create a HASH_INDEX in this way
graph.createKeyIndex("name", Vertex.class, new Parameter("type", "UNIQUE_HASH_INDEX"));
Use NOTUNIQUE_HASH_INDEX in case the index is not unique.
For more information look at the docs: http://orientdb.com/docs/2.0/orientdb.wiki/Graph-Database-Tinkerpop.html#using-indices

Related

How to create indexes in mongoDB using code?

I searched this in the Internet and found db.collectionName.createIndex() method. But in this way the index must be set in terminal if local database or using some UI in Mongo Atlas.But when we share our code index won't be created at their end for their table.Is there any way to create an index using code like we do in sql while declaring a primary key.

DOMINO REST API get Collection sort column

Hi I'm trying to get a sorted Collection from the Domino Rest Api. My database name is "Test/JSON_Views.nsf" and my views name "List".
The endpoint I use is
**/Test/JSON_Views.nsf/api/data/collections/name/List?sortcolumn=title&sortorder=ascending&count=20
But the JSON-Response entries aren't sorting by title in ascending order.
Should I make any settings to the column properties in the designer? If I set descending there for the title-column it works. But I want to change the sorting in my external java-application.
Is my endpoint correct? I use this Domino API Docu as Reference.
Add an additional sorting to your title column:
This gives the API the possibility to sort by title in both directions. You can do this with other columns too so you are very flexible in sorting this way.
The doc says that if the column isn't sorted in design then the sortcolumn parameter has no effect, so the answer is "Yes" you should change the design of the desired column. If doing that is unworkable in whatever context you use it, then create a second view and use that instead.

jcr sql-2 get node name

i am working on aem 6.3 and would like to get page name
SELECT * FROM [cq:Page] WHERE ISDESCENDANTNODE("/content/Product/Silhouettes/Accessories/Bands/Headband")
If I need to retrieve name of the nodes using sql-2 , how do I achieve it?
You can specify column constraints like title, node name, etc this way -
SELECT nodeSet.name, nodeset.title
FROM [cq:Page] AS nodeSet
WHERE ISDESCENDANTNODE("/content/Product/Silhouettes/Accessories/Bands/Headband")
Note: the query tool in AEM(Tools -> Query) will not list the query results according to the columns you've mentioned, it will only list the node paths.
You can look at using /etc/importers/bulkeditor.html or AEM fiddle tool to visualize the query results based on column constraints.
If you want to achieve this programmatically, you can use the same query as you've mentioned in your question and use javax.jcr.query.* and javax.jcr.Node.* API's to retrieve just about any property from the query result. This article here should help you achieve this programatically.
Use the ResourceResolver API to execute and obtain the query results:
final Iterator<Resource> pagesIterator = resolver.findResources('<your_query_here>', javax.jcr.query.Query.JCR_SQL2);
while (pagesIterator.hasNext()) {
final Resource pageResource = pagesIterator.next();
LOG.info(pageResource.getName());
}
However, please note that if you are using any version higher then CQ 5.6, you should use instead the Page API.
In this case, the listChildren(Filter<Page> filter, boolean deep) method will do the job.
The PageFilter parameter may be used if you want to filter through pages of some kind. So if no extra criteria for your page finding algorithm, your may pass null or a new empty object.
The boolean parameter: if false it returns only direct child pages, and if true would list all the descendant pages of the given page.
Therefore, the equivalent solution of the SQL Query which would provide you the same end results would be:
Iterator<Page> rootPageIterator = rootPage.listChildren(null, true);

upserting data in TitanDB

I am using TitanDB with Cassandra as storage and ElasticSearch as Index. I found out that everytime you add Vertex in TitanDB, it generates a unique identifier.
All the elements I am adding into it, has already an identifier, this has been added as property of the Vertex.
My question is:
If I will add again a Vertex with the same id, How does TitanDB recognise that it is a duplicate?
Is it possible update element on duplicate key ? Or you have first to make a query within TitanDB? If so, isn't it a terrible waste of time doing so?
There is no direct method for "upsert". As noted above, in the comment on the question, the "getOrCreate" approach is the standard way to do this. So, "yes" you would need to do a lookup via index on your identifier property.
Titan can detect duplicates if you establish your indexed property with a unique constraint:
mgmt = graph.openManagement()
name = mgmt.getPropertyKey('name')
mgmt.buildIndex('byNameUnique', Vertex.class).addKey(name).unique().buildCompositeIndex()
mgmt.commit()
If the same property value is applied twice now, an exception will be generated on commit of the transaction. Use unique indexes wisely as they will affect performance especially if you expect heavy contention on the property that the unique is applied to.

Using SQLite Manager to create indexes

I've created and index named "setIndex" for table "mySets" on column "setID" with the SQLite Manager (firefox). In order for the app to use them in a query, do I have to specify anything like the index name when searching my table?
SELECT * FROM mySets WHERE setID='setMatrix'
No, you don't have anything more to do; you can't explicitly make SQLite use an index when running a query. The database engine (SQLite but that goes for all the others) will decide whether to use your index if it's there and if it considers it appropriate to do so.