How can I get a list of indexed keys in Janusgraph? - janusgraph

In Titan, I could get a list of indexed key using this stackoverflow post - https://stackoverflow.com/a/18497954/1647476. We switched to using Janusgraph 0.2.0. Does anyone know how can I get a list of indexed keys in Janusgraph?
Thank you.

In a Gremlin console
mgmt = graph.openManagement()
mgmt.getGraphIndexes(Vertex.class)
It will return a list of index names. If you want to know which field keys are associated to a particular index:
mgmt.getGraphIndex('my_index_name').getFieldKeys()
Please visit this gist for details about schema description

Related

How to make Country-State-City like search in elastic Search

I want to make dependent search like when user type country and select country then on next dropdown/text search result would be from that particular Countries state, after selecting state on next text search would only based on that selected state. can anyone help to achieve this kind thing via elastic search.
i am new to elastic Search and i had basic idea of it, but didn't get idea how to do this kind of stuff where i need to search from child and feel data like map
Fist, it is important to understand how Elasticsearch store its data. You can find this kind of info here: https://www.elastic.co/guide/en/elasticsearch/reference/master/documents-indices.html
So, basically what you need is build a query with two must terms.
One for the object type (Country, State, etc).
Other for the name ("Los Angeles", "Massachussets", etc). If you want a autocomplete feature you could add a wildcard query in your list. https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-wildcard-query.html
Obs: When you store your State object do not forget to store the Country name together. Since Elasticsearch is non relational you have to have Country name indexed in the State document.
Hope that it helps

Index ID identification in Elasticsearch/Kibana visualization

"kibanaSavedObjectMeta": {
"searchSourceJSON": "{\"index\":\"4eb9f840-3969-11e8-ae19-552e148747c3\",\"filter\":[],\"query\":{\"language\":\"lucene\",\"query\":\"\"}}"
}
The above mentioned snippet is a exported JSON of a Kibana visualization. Without exporting this json is there a direct way to get this
\"index\":\"4eb9f840-3969-11e8-ae19-552e148747c3\ index id.
And if i am not wrong this is supposed to be the index id as its common across visualization with same index.
So, you can retrieve all index patterns using this query
GET .kibana/_search?q=type:index-pattern&size=100
Additionally, you can retrieve a specific set of index pattern given its name using
GET .kibana/_search?q=type:index-pattern%20AND%20index-pattern.title:indexname
Similarly, regarding visualizations, you can retrieve one by name using
GET .kibana/_search?q=type:visualization%20AND%20visualization.title:vizname

Lucene: Filter query by doc ID

I want to have in the search response only documents with specified doc id. In stackoverflow I found this question (Lucene filter with docIds) but as far as I understand there is created the additional field in the document and then doing search by this field. Is there another way to deal with it?
Lucene's docids are intended only to be internal keys. You should not be using them as search keys, or storing them for later use. Those ids are subject to change without warning. They will be changed when updating or reindexing documents, and can change at other times, such as segment merges, as well.
If you want your documents to have a unique identifier, you should generate that key separate from the docId, and index it as a field in your document.

Titan 1.0 mixed index is not working with warning - Query requires iterating over all vertices

I am using Titan 1.0 with elasticsearch as backend.
From the titan documentation, I learned that for using elasticsearch, we use mixedIndex while building indexes.
Here is my use case and problem:
I am creating a graph database for registration data of a book store, for the data I have registration time, and other personal infos such as name and age. I want to query all the users that registered during given time range, in another words, I want a numeric comparison function for the query. This is how I create the index:
PropertyKey propertyKey = mgmt.makePropertyKey("registTime").dataType(Date.class)
.cardinality(Cardinality.SINGLE).make()
timeIndex = mgmt.buildIndex("registeredTime",Vertex.class)
.addKey("registTime", Mapping.TEXTSTRING.asParameter())
.buildMixedIndex("search");
The timeIndex is created successfully, however, when I want to query the registered time with:
g.V().has("registTime", gt("2015-01-01 00:00:00.000+0000"))
it gives me:
WARN com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx - Query requires iterating over all vertices [()]. For better performance, use indexes
and it gives me an empty result, though I checked with gremlin command and confirmed the data is right there. Am I doing anything wrong? How can I solve this problem?
This error means that index has not been ENABLED yet.
Titan indexes have INSTALLED, REGISTERED, ENABLED and DISABLED states. For more information, have a look here.
You need to set the index state to ENABLED before you use it. Otherwise, you'll get this warning.
This is how you enable the index.
mgmt = graph.openManagement()
mgmt.updateIndex(mgmt.getGraphIndex("registeredTime"), SchemaAction.ENABLE).get()
mgmt.commit()
Then wait for it until it switches,
ManagementSystem.awaitGraphIndexStatus(graph, propertyKeyIndexName)
.status(SchemaStatus.ENABLED)
.timeout(10, ChronoUnit.MINUTES) // set timeout to 10 min
.call();
So from now on, all added data will be indexed. If you want to index already added data:
mgmt = graph.openManagement()
mgmt.updateIndex(mgmt.getGraphIndex("registeredTime"), SchemaAction.REINDEX).get()
mgmt.commit()
For more, read the docs here and here

How to sort Search Results based on a Field Value in Lucene-3.0.2?

I have googled a lot and also searched in stackoverflow.com about how to sort search results based on a Field Value in Lucene 3.0.2, but not found any useful data. I'm getting the search results from the index, based on the user query but not able to sort the results based on field like id or date.
I have pasted my code here for searching lucene index- http://pastie.org/1033974.
Please help me to solve this problem. If you provide me some example code or links where i can find that will be better.
Thanks
The IndexSearcher class has a couple of search methods that takes a Sort Object that you have to use. A Sort object is basically a wrapper around one or more SortField objects which hold details on what field to sort on and how.
Note that a field must be indexed to be used for sorting.

Resources